初学java,练习使用ant, 为了将java 工程打包成war包发布,练习者写了一个build.xml文件。花了半个下午的时间啊。 <?xml version="1.0" encoding="UTF-8"?> <project name="AdsTestKit" default="website.pakege" basedir="."> <property name="regressionproj.name" value="RegressionTest" /> <property name="performanceproj.name" value="PerformanceTest" /> <property name="proj-regression.dir" value="regression" /> <property name="proj-performance.dir" value="performance" /> <property name="proj-common.dir" value="common" /> <property name="src.regression.dir" value="${proj-regression.dir}/src" /> <property name="src.performance.dir" value="${proj-performance.dir}/src" /> <property name="src.common.dir" value="${proj-common.dir}/src" /> <property file="build.properties"/> <property name="build.dir" value="build"/> <property name="build.classes" value="${build.dir}/classes"/> <property name="build.classes.regression" value="${build.classes}/regression"/> <property name="build.classes.performance" value="${build.classes}/performance"/> <property name="build.classes.common" value="${build.classes}/common/"/> <property name="build.package" value="${build.dir}/package"/> <property name="build.package.config" value="${build.package}/config"/> <property name="dist.dir" value="dist"/> <property name="dist.lib" value="${dist.dir}/lib"/> <property name="lib.regression.dir" value="${proj-regression.dir}/lib"/> <property name="lib.performance.dir" value="${proj-performance.dir}/lib"/> <property name="lib.common.dir" value="${proj-common.dir}/lib"/> <property name="performance.config.dir" value="performance/config/config"/> <property name="regression.data.dir" value="regression/data"/> <property name="regression.testreport.dir" value="regression/testreport"/> <property name="regression.logs.dir" value="regression/logs"/> <property name="regression.res.dir" value="regression/res"/> <property name="webpage.dir" value="web"/> <property name="regressionjsp.dir" value="${webpage.dir}/regression-jsp"/> <property name="performancejsp.dir" value="${webpage.dir}/performance-jsp"/> <property name="image.dir" value="image"/> <!--property name="axis2.dir" value="../axis2-1.5.1"/--> <property name="axis2.dir" value="D:/ProgramFiles/axis2-1.5.1-bin/axis2-1.5.1/lib"/> <property file="website structure"/> <property name="archive.name" value="AdsTestKit"/> <property name="archive.suffix" value="war"/> <property name="webbase.dir" value="website"/> <property name="webimage.dir" value="${webbase.dir}/image"/> <property name="webinfo.dir" value="${webbase.dir}/WEB-INF"/> <property name="weblib.dir" value="${webinfo.dir}/lib"/> <property name="webclasses.dir" value="${webinfo.dir}/classes"/> <property name="performance.dir" value="${webbase.dir}/performance"/> <property name="perf_report.dir" value="${performance.dir}/testreport"/> <property name="regression.dir" value="${webbase.dir}/regression"/> <property name="css.dir" value="${regression.dir}/css"/> <property name="data.dir" value="${regression.dir}/data"/> <property name="logs.dir" value="${regression.dir}/logs"/> <property name="res.dir" value="${regression.dir}/res"/> <property name="regr_report.dir" value="${regression.dir}/testreport"/> <path id="project.classpath"> <fileset dir="${lib.regression.dir}"> <include name="*.jar"/> </fileset> <fileset dir="${lib.performance.dir}"> <include name="*.jar"/> </fileset> <fileset dir="${lib.common.dir}"> <include name="*.jar"/> </fileset> <fileset dir="${axis2.dir}"> <include name="*.jar"/> </fileset> <pathelement path="${build.classes}"/> </path> <target name="clean"> <delete dir="${build.dir}"/> <delete dir="${dist.dir}"/> <delete dir="${webbase.dir}"/> </target> <target name="prepare" depends="clean"> <mkdir dir="${build.dir}"/> <mkdir dir="${build.classes}"/> <mkdir dir="${build.classes.regression}"/> <mkdir dir="${build.classes.performance}"/> <mkdir dir="${build.classes.common}"/> <mkdir dir="${build.package}"/> <mkdir dir="${dist.dir}"/> <mkdir dir="${dist.lib}"/> <mkdir dir="${webbase.dir}"/> <mkdir dir="${webimage.dir}"/> <mkdir dir="${webinfo.dir}"/> <mkdir dir="${weblib.dir}"/> <mkdir dir="${webclasses.dir}"/> <mkdir dir="${performance.dir}"/> <mkdir dir="${perf_report.dir}"/> <mkdir dir="${regression.dir}"/> <mkdir dir="${css.dir}"/> <mkdir dir="${data.dir}"/> <mkdir dir="${logs.dir}"/> <mkdir dir="${res.dir}"/> <mkdir dir="${regr_report.dir}"/> </target> <target name="compile" depends="prepare"> <javac target="1.6" debug="on" fork="true" destdir="${build.classes.regression}" srcdir="${src.regression.dir}" classpathref="project.classpath"/> <javac target="1.6" debug="on" fork="true" destdir="${build.classes.performance}" srcdir="${src.performance.dir}" classpathref="project.classpath"/> <javac target="1.6" debug="on" fork="true" destdir="${build.classes.common}" srcdir="${src.common.dir}" classpathref="project.classpath"/> </target> <target name="jar" depends="compile"> <jar destfile="${build.package}/${regressionproj.name}.jar"> <fileset dir="${build.classes.regression}"/> </jar> <jar destfile="${build.package}/${performanceproj.name}.jar"> <fileset dir="${build.classes.performance}"/> </jar> </target> <target name="copy.to.package" depends="clean,jar"> <copy toDir="${dist.lib}"> <fileset dir="${build.package}"> <include name="*.jar"/> </fileset> </copy> <copy toDir="${webbase.dir}"> <fileset dir="${webpage.dir}"> <include name="*.html"/> </fileset> </copy> <copy toDir="${webinfo.dir}"> <fileset dir="${webpage.dir}"> <include name="*.xml"/> </fileset> </copy> <copy toDir="${weblib.dir}"> <fileset dir="${dist.lib}"> <include name="*.jar"/> </fileset> <fileset dir="${axis2.dir}"> <include name="*.jar"/> </fileset> <fileset dir="${lib.regression.dir}"> <include name="*.jar"/> </fileset> <fileset dir="${lib.performance.dir}"> <include name="*.jar"/> </fileset> <fileset dir="${lib.common.dir}"> <include name="*.jar"/> </fileset> </copy> <copy toDir="${webclasses.dir}"> <fileset dir="${performance.config.dir}"> <include name="adperf.properties"/> </fileset> <fileset dir="${build.classes.common}"> <include name="**"/> </fileset> </copy> <copy toDir="${performance.dir}"> <fileset dir="${performancejsp.dir}"> <include name="*.jsp"/> </fileset> </copy> <copy toDir="${performance.dir}"> <fileset dir="${performancejsp.dir}"> <include name="*.jsp"/> </fileset> </copy> <copy toDir="${regression.dir}"> <fileset dir="${regressionjsp.dir}"> <include name="*.jsp"/> </fileset> </copy> <copy toDir="${css.dir}"> <fileset dir="${regression.testreport.dir}"> <include name="*.css"/> </fileset> </copy> <copy toDir="${data.dir}"> <fileset dir="${regression.data.dir}"> <include name="**"/> </fileset> </copy> <copy toDir="${logs.dir}"> <fileset dir="${regression.logs.dir}"> <include name="*.*"/> </fileset> </copy> <copy toDir="${res.dir}"> <fileset dir="${regression.res.dir}"> <include name="**"/> </fileset> </copy> <copy toDir="${regr_report.dir}"> <fileset dir="${regression.testreport.dir}"> <include name="*.css"/> </fileset> </copy> <copy toDir="${webimage.dir}"> <fileset dir="${image.dir}"> <include name="**"/> </fileset> </copy> </target> <target name="website.pakege" depends="copy.to.package"> <jar destfile="${dist.dir}/${archive.name}.${archive.suffix}"> <fileset dir="${webbase.dir}"/> </jar> </target> </project>