<?xml version="1.0" encoding="UTF-8"?> <project name="${project.name}" basedir="." default="main"> <property file="build.properties" /> <property name="classes.dir" value="${webapp.dir}/WEB-INF/classes" /> <property name="lib.dir" value="${webapp.dir}/WEB-INF/lib" /> <target name="clean" description="清除舊的工程文件目錄"> <echo>清除舊的工程文件目錄</echo> <delete dir="${classes.dir}" /> <delete dir="${build.dir}" /> <delete dir="${tomcat.home}/webapps" /> <delete dir="${tomcat.home}/work" /> </target> <target name="init" description="初始化"> <echo>初始化</echo> <tstamp /> <mkdir dir="${classes.dir}" /> <mkdir dir="${build.dir}" /> <mkdir dir="${tomcat.home}/webapps" /> <mkdir dir="${tomcat.home}/work" /> </target> <path id="application-lib"> <fileset dir="${lib.dir}" includes="**/*.jar" /> </path> <target name="compile-java" depends="init" description="編譯源代碼"> <echo>編譯源代碼</echo> <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="on" encoding="utf-8"> <classpath> <path refid="application-lib" /> </classpath> </javac> <copy todir="${classes.dir}"> <fileset dir="${src.dir}/resources" includes="**/*.*" /> </copy> </target> <path id="external-lib-path"> <fileset dir="${external-lib}" includes="**/*.jar" /> </path> <target name="compile-junit-test" depends="compile-java" description="編譯測試代碼"> <echo>編譯測試代碼</echo> <mkdir dir="${build.dir}/test/classes" /> <javac srcdir="${test.dir}" destdir="${build.dir}/test/classes" includeantruntime="on" encoding="utf-8"> <classpath> <pathelement location="${classes.dir}" /> <path refid="application-lib" /> <path refid="external-lib-path" /> </classpath> </javac> </target> <!-- JUNIT4測試TARGET --> <target name="junit" depends="compile-junit-test" description="運行測試JUNIT代碼"> <echo>運行測試JUNIT代碼</echo> <mkdir dir="${build.dir}/test/report" /> <junit printsummary="yes" failureproperty="junit.tests.failure" showoutput="on"> <classpath> <path location="${build.dir}/test/classes" /> <path location="${classes.dir}" /> <path refid="application-lib" /> <path refid="external-lib-path" /> </classpath> <formatter type="xml" /> <batchtest fork="yes" todir="${build.dir}/test/report"> <fileset dir="${test.dir}" includes="**/*Test.java" /> </batchtest> </junit> <junitreport todir="${build.dir}/test/report"> <fileset dir="${build.dir}/test/report"> <include name="**/TEST-*.xml" /> </fileset> <report todir="${build.dir}/test/report" /> </junitreport> </target> <target name="war" depends="compile-java" description="打包WAR文件"> <echo>打包WAR文件</echo> <mkdir dir="${build.dir}/war" /> <war warfile="${build.dir}/war/${webapp.name}.war" webxml="${webapp.dir}/WEB-INF/web.xml"> <lib dir="${lib.dir}" /> <classes dir="${classes.dir}" /> <fileset dir="${webapp.dir}" /> </war> </target> <target name="publish" depends="war" description="發佈WAR文件到TOMCAT服務器中"> <echo>發佈WAR文件到TOMCAT服務器中</echo> <copy todir="${tomcat.home}/webapps"> <fileset dir="${build.dir}/war" includes="${webapp.name}.war" /> </copy> </target> <target name="main" depends="clean,junit,publish" description="運行默認的TARGET"> <echo>運行默認的TARGET</echo> </target> </project>
ANT結合實際項目、JUNIT4測試詳細配置文件(可作為模板使用)
最新推荐文章于 2024-09-12 09:04:49 发布