灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2817回复:0

java应用程序Ant通用模板

楼主#
更多 发布于:2012-09-08 09:40


build.ant
[html]
<?xml version="1.0" encoding="UTF-8"?>
<project default="output" basedir=".">
    <tstamp>
    </tstamp>
    <property file="build.properties" />
    <property file="version.properties" />
    <property environment="env" />
    <property name="src.dir" value="${basedir}/src" />
    <property name="lib.dir" value="${basedir}" />
    <property name="build.dir" value="${basedir}/build" />
    <property name="output.dir" value="${basedir}/output" />

    <!-- 主任务 -->
    <target name="output">
        <antcall target="clean" />
        <antcall target="init" />
        <antcall target="getversion" />
        <antcall target="build" />
        <antcall target="copy" />
        <antcall target="copylib" />
        <antcall target="makejar" />
    </target>

    <!-- 定义ClassPath -->
    <path id="project.classpath">
        <fileset file="${lib.dir}/*.jar" />
    </path>

    <!-- 初始化任务, 清除目录 -->
    <target name="clean">
        <delete dir="${build.dir}" />
    </target>

    <!-- 初始化任务, 创建目录 -->
    <target name="init">
        <mkdir dir="${build.dir}" />
        <mkdir dir="${output.dir}" />
    </target>

    <!-- 获取版本信息 -->
    <target name="getversion">
        <propertyfile file="version.properties" comment="This is Version File">
            <entry key="buildDate" type="date" value="now" pattern="yyyy-MM-dd HH:mms" />
        </propertyfile>
        <property file="version.properties" />
        <copy todir="${build.dir}">
            <fileset dir=".">
                <include name="version.properties" />
            </fileset>
        </copy>
    </target>

    <!-- 编译java程序  -->
    <target name="build">
        <javac srcdir="${src.dir}" destdir="${build.dir}" debug="on">
            <classpath refid="project.classpath" />
        </javac>
    </target>

    <target name="copy">
        <!-- 复制生产环境的配置文件配置文件 -->
        <copy todir="${build.dir}" overwrite="true">
            <fileset dir="${src.dir}">
                <include name="**/*.properties" />
                <include name="**/*.xml" />
            </fileset>
        </copy>
    </target>

    <target name="copylib">
        <mkdir dir="${output.dir}/lib" />
        <copy todir="${output.dir}/lib">
            <fileset dir="${lib.dir}">
                <include name="*.jar" />
            </fileset>
        </copy>
    </target>

    <!-- 打包jar文件  -->
    <target name="makejar">
        <jar destfile="${output.dir}/${projectname}-${DSTAMP}-${version}.jar" basedir="${build.dir}" >
            <manifest>
                <attribute name="Main-Class" value="com.fsti.MyTest" />
            </manifest>
        </jar>
    </target>
</project>
build.properties
[plain]
# build.properties
projectname=testproject
version.properties
[plain]
#This is Version File
#Tue Apr 30 18:14:42 CST 2011
version=1.0.0
buildDate=2011-04-30 18\:14\:42



喜欢0 评分0
游客

返回顶部