今天学习了使用ant进行打包,记录如下:
<project name="platform-war" default="release" basedir=".">
<property file="${resource.home}/database.conf.properties" />
<!-- ==================== File and Directory Names ======================== -->
<property name="build.home" value="${basedir}/target/build" />
<property name="dist.home" value="${basedir}/target/dist" />
<property name="deploy.path" value="${dist.home}/platform" />
<property name="src.home" value="${basedir}/src/main/java" />
<property name="resource.home" value="${basedir}/src/main/resources" />
<property name="web.home" value="${basedir}/src/main/webapp" />
<property name="lib.compile.home" value="${basedir}/antlib" />
<property name="lib.runtime.home" value="${web.home}/WEB-INF/lib" />
<tstamp prefix="build">
<format property="dt" pattern="yyyyMMdd.HHmmss.SSS" />
</tstamp>
<tstamp>
<format property="deploy.debug.tstamp" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo>开始打包:${deploy.debug.tstamp}</echo>
<path id="compile.web.classpath">
<fileset dir="${lib.compile.home}">
<include name="*.jar" />
</fileset>
<fileset dir="${lib.runtime.home}">
<include name="*.jar" />
</fileset>
</path>
<target name="-clean-compile" description="清除编译过的文件和发布的文件">
<delete dir="${build.home}" />
<delete dir="${dist.home}" />
</target>
<target name="clean" depends="-clean-compile" description="深层清除发布环境,删除所有预编译文件,以重新编译所有Java类和重新复制所有文件">
</target>
<target name="-prepare" description="为发布工作进行准备">
<mkdir dir="${build.home}/java" />
<mkdir dir="${build.home}/classes" />
<mkdir dir="${dist.home}" />
</target>
<target name="-compile" depends="-prepare" description="">
<tstamp>
<format property="deploy.debug.tstampcompile" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo>开始正在编译java:${deploy.debug.tstampcompile}</echo>
<copy todir="${build.home}/java" preservelastmodified="true" encoding="UTF-8" outputencoding="UTF-8">
<fileset dir="${src.home}">
<include name="**/*.java" />
<exclude name="**/CVS/" />
<exclude name="**/SVN/" />
</fileset>
</copy>
<javac srcdir="${build.home}/java" destdir="${build.home}/classes" nowarn="true" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}" encoding="UTF-8" source="1.7" target="1.7">
<classpath refid="compile.web.classpath" />
</javac>
</target>
<target name="compile" depends="-compile" description="编译需要的Java类(增量),并直接将编译后的结果复制(仅更新文件)到发布路径">
</target>
<target name="copy-web" description="发布Web内容到发布目录(仅更新文件)">
<tstamp>
<format property="deploy.debug.tstampcopyweb" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo>开始copyweb:${deploy.debug.tstampcopyweb}</echo>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir="${web.home}">
</fileset>
</copy>
<copy todir="${deploy.path}/WEB-INF/classes" includeEmptyDirs="false">
<fileset dir="${build.home}/classes">
</fileset>
<fileset dir="${resource.home}">
</fileset>
</copy>
</target>
<target name="release" depends="-clean-compile,-prepare,compile,copy-web" description="打包成war">
<tstamp>
<format property="deploy.debug.tstamprelease" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo>开始打包war:${deploy.debug.tstamprelease}</echo>
<war destfile="${dist.home}/platform.war">
<fileset dir="${dist.home}/platform">
</fileset>
</war>
<tstamp>
<format property="deploy.debug.tstampover" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo>结束打包:${deploy.debug.tstampover}</echo>
</target>
</project>