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