ANT結合實際項目、JUNIT4測試詳細配置文件(可作為模板使用)

<?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>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值