build.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<project name="yybar" basedir="." default="build">
<!--Load properties file
<property file="build.properties" />
-->
<!-- App name-dependent settings. -->
<property name="appname" value="${ant.project.name}" />
<property name="deploy.resin" value="D:/resin3.0.19/webapps" />
<property name="deploy.tomcat" value="D:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps" />
<property name="src.dir" value="${basedir}/src" />
<property name="data.dir" value="${basedir}/data" />
<property name="lib.dir" value="${basedir}/lib" />
<property name="web.dir" value="${src.dir}/web" />
<property name="build.dir" value="${basedir}/build" />
<property name="dist.dir" value="${basedir}/dist" />
<property name="war.dir" value="${build.dir}/${appname}" />
<property name="webinf.dir" value="${war.dir}/WEB-INF" />
<property name="class.dir" value="${war.dir}/WEB-INF/classes" />
<property name="conf.dir" value="${src.dir}/conf" />
<property name="conf.classes" value="${src.dir}/conf/classes" />
<property name="conf.webinf" value="${src.dir}/conf/WEB-INF" />
<property name="warlib.dir" value="${war.dir}/WEB-INF/lib" />
<property name="war.file" value="${dist.dir}/${appname}.war" />
<property name="views.dir" value="${src.dir}/java/com/easou/${appname}/views" />
<property name="controller.dir" value="${src.dir}/java/com/easou/${appname}/controller" />
<property name="model.dir" value="${src.dir}/java/com/easou/${appname}/model" />
<property name="util.dir" value="${src.dir}/java/com/easou/${appname}/util" />
<property name="exception.dir" value="${src.dir}/java/com/easou/${appname}/exception" />
<property name="test" value="${basedir}/test" />
<property name="test.src" value="${test}/java" />
<property name="test.classesdir" value="${build.dir}/test/classes" />
<property name="test.libpath" value="${test}/lib" />
<property name="test.confdir" value="${test}/etc" />
<property name="test.reportdir" value="${test}/report" />
<tstamp>
<format property="build.date" pattern="yyyy-MM-dd HH:mm" />
</tstamp>
<path id="master-classpath" description="Master CLASSPATH for this script">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
<pathelement path="${class.dir}" />
</path>
<path id="test.lib">
<fileset dir="${test.libpath}">
<include name="**/*.jar" />
</fileset>
</path>
<path id="lib.total">
<path refid="master-classpath" />
<path refid="test.lib" />
</path>
<target name="init" description="Setup for build script">
<mkdir dir="${class.dir}" />
<mkdir dir="${warlib.dir}" />
<mkdir dir="${conf.dir}" />
<mkdir dir="${conf.classes}" />
<mkdir dir="${conf.webinf}" />
<mkdir dir="${web.dir}" />
<mkdir dir="${lib.dir}" />
<mkdir dir="${data.dir}" />
<mkdir dir="${views.dir}" />
<mkdir dir="${model.dir}" />
<mkdir dir="${controller.dir}" />
<mkdir dir="${util.dir}" />
<mkdir dir="${exception.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- ======================================================= -->
<!-- Convert native properties files to ascii format. -->
<!-- ======================================================= -->
<target name="unicode">
<delete>
<fileset dir="${conf.classes}" includes="resources*.properties" />
</delete>
<native2ascii encoding="gb2312" src="${conf.classes}" dest="${conf.classes}" includes="resources*.src" ext=".properties" />
</target>
<target name="updateweb" depends="init" description="Copies web related files to WAR directory">
<copy todir="${war.dir}">
<fileset dir="${web.dir}">
<include name="**/*" />
</fileset>
</copy>
<copy todir="${war.dir}">
<fileset dir="${views.dir}" />
</copy>
</target>
<target name="updatelib" depends="init" description="Copies JAR files to WAR directory">
<copy todir="${warlib.dir}">
<fileset dir="${lib.dir}">
<exclude name="*junit*.jar" />
<exclude name="*spring-mock*.jar" />
</fileset>
</copy>
</target>
<target name="deleteconfig" depends="init" description="Deletes config files from WAR directory">
<delete failonerror="false">
<fileset dir="${war.dir}">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</delete>
</target>
<target name="updateconfig" depends="init,unicode" description="Copies configuration files to WAR directory">
<copy todir="${class.dir}">
<fileset dir="${conf.classes}">
<include name="**/*.xml" />
<include name="**/*.properties" />
<include name="**/*.src" />
</fileset>
</copy>
<copy todir="${webinf.dir}" preservelastmodified="true">
<fileset dir="${conf.webinf}">
<include name="**/*.xml" />
<include name="**/*.tld" />
</fileset>
</copy>
</target>
<!-- ======================================================= -->
<!-- Compile all classes. -->
<!-- ======================================================= -->
<target name="compile" depends="init" description="Compiles .java files to WAR directory">
<javac srcdir="${src.dir}" destdir="${class.dir}" encoding="utf-8" debug="on" deprecation="yes" includes="**" optimize="on" failonerror="true">
<classpath refid="master-classpath" />
</javac>
</target>
<target name="build" depends="compile,updateweb,updateconfig,updatelib" />
<target name="rebuild" depends="clean,compile,updateweb,updateconfig,updatelib" />
<target name="dist" depends="rebuild" description="Assembles WAR file">
<war destfile="${war.file}" webxml="${conf.webinf}/web.xml">
<fileset dir="${war.dir}">
<include name="**/*.*" />
<exclude name="**/web.xml" />
<exclude name="**/test/*.class" />
</fileset>
</war>
</target>
<target name="deploy" depends="dist" description="Deploys WAR file to deploy.dir">
<delete failonerror="true" dir="${deploy.resin}/${appname}" />
<copy file="${war.file}" todir="${deploy.resin}" />
</target>
<!-- ======================================================= -->
<!-- Install targets. -->
<!-- ======================================================= -->
<target name="resininstall">
<copy todir="${deploy.resin}/${appname}">
<fileset dir="${war.dir}" />
</copy>
</target>
<target name="resin" depends="updateweb, updatelib, updateconfig, resininstall" />
<target name="tomcatinstall">
<copy todir="${deploy.tomcat}/${appname}">
<fileset dir="${war.dir}" />
</copy>
</target>
<target name="tomcat" depends="updateweb, updatelib, updateconfig, tomcatinstall" />
<!-- ======================================================= -->
<!-- Clean up various files and directories. -->
<!-- ======================================================= -->
<target name="clean" description="Deletes files from WAR directory">
<delete failonerror="false">
<fileset dir="${war.dir}">
<include name="**/*.*" />
</fileset>
</delete>
<delete failonerror="false">
<fileset dir="${dist.dir}">
<include name="**/*" />
</fileset>
</delete>
<delete failonerror="false">
<fileset dir="${dist.dir}">
<include name="**/*" />
</fileset>
</delete>
</target>
<!-- ======================================================= -->
<!-- Assemble WAR module. -->
<!-- ======================================================= -->
<target name="unpackwar" depends="compile, unicode, updateweb, updatelib, updateconfig" />
<!--
<target name="test" depends="unpackwar">
printsummary属性为true会将测试的结果简单的显示出来
<junit printsummary="true" showoutput="yes" filtertrace="false">
<classpath refid="master-classpath" />
batchtest元素定义测试文件以运行(其类名称以Test结尾)
<batchtest fork="yes">
<formatter type="plain" />
<fileset dir="${class.dir}">
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
</target>
-->
<!-- ======================================================= -->
<!-- Compile all testsuite classes. -->
<!-- ======================================================= -->
<target name="testcompile">
<mkdir dir="${test.classesdir}" />
<copy todir="${test.classesdir}">
<fileset dir="${test.confdir}" includes="*.properties" />
<fileset dir="${conf.classes}" includes="*.*" excludes="spring.properties" />
</copy>
<javac encoding="utf-8" debug="on" deprecation="yes" destdir="${test.classesdir}" includes="**" optimize="on" srcdir="${test.src}">
<classpath refid="lib.total" />
<classpath>
<pathelement location="${class.dir}" />
</classpath>
</javac>
</target>
<!-- ======================================================= -->
<!-- Batch Test -->
<!-- ======================================================= -->
<target name="testAll" depends="unpackwar, testcompile">
<!--ant junit -->
<mkdir dir="${test.reportdir}" />
<junit printsummary="no" fork="yes" haltonfailure="off">
<classpath>
<pathelement location="${class.dir}" />
<pathelement location="${test.classesdir}" />
<pathelement location="${conf.webinf}" />
<!-- strutsTest must require /WEB-INF/web.xml in classpath -->
<pathelement location="${war.dir}" />
</classpath>
<classpath refid="master-classpath" />
<classpath refid="test.lib" />
<formatter type="xml" />
<formatter type="plain" usefile="no" />
<test name="com.easou.yybar.AllTests" todir="${test.reportdir}" />
<!--
<batchtest todir="${test.reportdir}">
<fileset dir="${test.classesdir}">
<include name="**/*Test.class" />
<exclude name="**/*TestCase.class" />
<exclude name="**/*$*.class" />
</fileset>
</batchtest>
-->
</junit>
</target>
<target name="test-reports" description="Generate test reports">
<junitreport todir="${test.reportdir}">
<fileset dir="${test.reportdir}">
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${test.reportdir}" />
</junitreport>
</target>
</project>
<project name="yybar" basedir="." default="build">
<!--Load properties file
<property file="build.properties" />
-->
<!-- App name-dependent settings. -->
<property name="appname" value="${ant.project.name}" />
<property name="deploy.resin" value="D:/resin3.0.19/webapps" />
<property name="deploy.tomcat" value="D:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps" />
<property name="src.dir" value="${basedir}/src" />
<property name="data.dir" value="${basedir}/data" />
<property name="lib.dir" value="${basedir}/lib" />
<property name="web.dir" value="${src.dir}/web" />
<property name="build.dir" value="${basedir}/build" />
<property name="dist.dir" value="${basedir}/dist" />
<property name="war.dir" value="${build.dir}/${appname}" />
<property name="webinf.dir" value="${war.dir}/WEB-INF" />
<property name="class.dir" value="${war.dir}/WEB-INF/classes" />
<property name="conf.dir" value="${src.dir}/conf" />
<property name="conf.classes" value="${src.dir}/conf/classes" />
<property name="conf.webinf" value="${src.dir}/conf/WEB-INF" />
<property name="warlib.dir" value="${war.dir}/WEB-INF/lib" />
<property name="war.file" value="${dist.dir}/${appname}.war" />
<property name="views.dir" value="${src.dir}/java/com/easou/${appname}/views" />
<property name="controller.dir" value="${src.dir}/java/com/easou/${appname}/controller" />
<property name="model.dir" value="${src.dir}/java/com/easou/${appname}/model" />
<property name="util.dir" value="${src.dir}/java/com/easou/${appname}/util" />
<property name="exception.dir" value="${src.dir}/java/com/easou/${appname}/exception" />
<property name="test" value="${basedir}/test" />
<property name="test.src" value="${test}/java" />
<property name="test.classesdir" value="${build.dir}/test/classes" />
<property name="test.libpath" value="${test}/lib" />
<property name="test.confdir" value="${test}/etc" />
<property name="test.reportdir" value="${test}/report" />
<tstamp>
<format property="build.date" pattern="yyyy-MM-dd HH:mm" />
</tstamp>
<path id="master-classpath" description="Master CLASSPATH for this script">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
<pathelement path="${class.dir}" />
</path>
<path id="test.lib">
<fileset dir="${test.libpath}">
<include name="**/*.jar" />
</fileset>
</path>
<path id="lib.total">
<path refid="master-classpath" />
<path refid="test.lib" />
</path>
<target name="init" description="Setup for build script">
<mkdir dir="${class.dir}" />
<mkdir dir="${warlib.dir}" />
<mkdir dir="${conf.dir}" />
<mkdir dir="${conf.classes}" />
<mkdir dir="${conf.webinf}" />
<mkdir dir="${web.dir}" />
<mkdir dir="${lib.dir}" />
<mkdir dir="${data.dir}" />
<mkdir dir="${views.dir}" />
<mkdir dir="${model.dir}" />
<mkdir dir="${controller.dir}" />
<mkdir dir="${util.dir}" />
<mkdir dir="${exception.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- ======================================================= -->
<!-- Convert native properties files to ascii format. -->
<!-- ======================================================= -->
<target name="unicode">
<delete>
<fileset dir="${conf.classes}" includes="resources*.properties" />
</delete>
<native2ascii encoding="gb2312" src="${conf.classes}" dest="${conf.classes}" includes="resources*.src" ext=".properties" />
</target>
<target name="updateweb" depends="init" description="Copies web related files to WAR directory">
<copy todir="${war.dir}">
<fileset dir="${web.dir}">
<include name="**/*" />
</fileset>
</copy>
<copy todir="${war.dir}">
<fileset dir="${views.dir}" />
</copy>
</target>
<target name="updatelib" depends="init" description="Copies JAR files to WAR directory">
<copy todir="${warlib.dir}">
<fileset dir="${lib.dir}">
<exclude name="*junit*.jar" />
<exclude name="*spring-mock*.jar" />
</fileset>
</copy>
</target>
<target name="deleteconfig" depends="init" description="Deletes config files from WAR directory">
<delete failonerror="false">
<fileset dir="${war.dir}">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</delete>
</target>
<target name="updateconfig" depends="init,unicode" description="Copies configuration files to WAR directory">
<copy todir="${class.dir}">
<fileset dir="${conf.classes}">
<include name="**/*.xml" />
<include name="**/*.properties" />
<include name="**/*.src" />
</fileset>
</copy>
<copy todir="${webinf.dir}" preservelastmodified="true">
<fileset dir="${conf.webinf}">
<include name="**/*.xml" />
<include name="**/*.tld" />
</fileset>
</copy>
</target>
<!-- ======================================================= -->
<!-- Compile all classes. -->
<!-- ======================================================= -->
<target name="compile" depends="init" description="Compiles .java files to WAR directory">
<javac srcdir="${src.dir}" destdir="${class.dir}" encoding="utf-8" debug="on" deprecation="yes" includes="**" optimize="on" failonerror="true">
<classpath refid="master-classpath" />
</javac>
</target>
<target name="build" depends="compile,updateweb,updateconfig,updatelib" />
<target name="rebuild" depends="clean,compile,updateweb,updateconfig,updatelib" />
<target name="dist" depends="rebuild" description="Assembles WAR file">
<war destfile="${war.file}" webxml="${conf.webinf}/web.xml">
<fileset dir="${war.dir}">
<include name="**/*.*" />
<exclude name="**/web.xml" />
<exclude name="**/test/*.class" />
</fileset>
</war>
</target>
<target name="deploy" depends="dist" description="Deploys WAR file to deploy.dir">
<delete failonerror="true" dir="${deploy.resin}/${appname}" />
<copy file="${war.file}" todir="${deploy.resin}" />
</target>
<!-- ======================================================= -->
<!-- Install targets. -->
<!-- ======================================================= -->
<target name="resininstall">
<copy todir="${deploy.resin}/${appname}">
<fileset dir="${war.dir}" />
</copy>
</target>
<target name="resin" depends="updateweb, updatelib, updateconfig, resininstall" />
<target name="tomcatinstall">
<copy todir="${deploy.tomcat}/${appname}">
<fileset dir="${war.dir}" />
</copy>
</target>
<target name="tomcat" depends="updateweb, updatelib, updateconfig, tomcatinstall" />
<!-- ======================================================= -->
<!-- Clean up various files and directories. -->
<!-- ======================================================= -->
<target name="clean" description="Deletes files from WAR directory">
<delete failonerror="false">
<fileset dir="${war.dir}">
<include name="**/*.*" />
</fileset>
</delete>
<delete failonerror="false">
<fileset dir="${dist.dir}">
<include name="**/*" />
</fileset>
</delete>
<delete failonerror="false">
<fileset dir="${dist.dir}">
<include name="**/*" />
</fileset>
</delete>
</target>
<!-- ======================================================= -->
<!-- Assemble WAR module. -->
<!-- ======================================================= -->
<target name="unpackwar" depends="compile, unicode, updateweb, updatelib, updateconfig" />
<!--
<target name="test" depends="unpackwar">
printsummary属性为true会将测试的结果简单的显示出来
<junit printsummary="true" showoutput="yes" filtertrace="false">
<classpath refid="master-classpath" />
batchtest元素定义测试文件以运行(其类名称以Test结尾)
<batchtest fork="yes">
<formatter type="plain" />
<fileset dir="${class.dir}">
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
</target>
-->
<!-- ======================================================= -->
<!-- Compile all testsuite classes. -->
<!-- ======================================================= -->
<target name="testcompile">
<mkdir dir="${test.classesdir}" />
<copy todir="${test.classesdir}">
<fileset dir="${test.confdir}" includes="*.properties" />
<fileset dir="${conf.classes}" includes="*.*" excludes="spring.properties" />
</copy>
<javac encoding="utf-8" debug="on" deprecation="yes" destdir="${test.classesdir}" includes="**" optimize="on" srcdir="${test.src}">
<classpath refid="lib.total" />
<classpath>
<pathelement location="${class.dir}" />
</classpath>
</javac>
</target>
<!-- ======================================================= -->
<!-- Batch Test -->
<!-- ======================================================= -->
<target name="testAll" depends="unpackwar, testcompile">
<!--ant junit -->
<mkdir dir="${test.reportdir}" />
<junit printsummary="no" fork="yes" haltonfailure="off">
<classpath>
<pathelement location="${class.dir}" />
<pathelement location="${test.classesdir}" />
<pathelement location="${conf.webinf}" />
<!-- strutsTest must require /WEB-INF/web.xml in classpath -->
<pathelement location="${war.dir}" />
</classpath>
<classpath refid="master-classpath" />
<classpath refid="test.lib" />
<formatter type="xml" />
<formatter type="plain" usefile="no" />
<test name="com.easou.yybar.AllTests" todir="${test.reportdir}" />
<!--
<batchtest todir="${test.reportdir}">
<fileset dir="${test.classesdir}">
<include name="**/*Test.class" />
<exclude name="**/*TestCase.class" />
<exclude name="**/*$*.class" />
</fileset>
</batchtest>
-->
</junit>
</target>
<target name="test-reports" description="Generate test reports">
<junitreport todir="${test.reportdir}">
<fileset dir="${test.reportdir}">
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${test.reportdir}" />
</junitreport>
</target>
</project>
其目录结构如下: