Ant脚本文件build.xml模版

<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject" basedir="." default="junit">

	<property name="src.dir" value="src" />
	<property name="classes.dir" value="bin" />
	<property name="jar.dir" value="jar" />
	<property name="srctest.dir" value="srctest" />
	<property name="classestest.dir" value="bintest" />
	<property name="lib.dir" value="lib" />
	<property name="report.dir" value="report" />
	
	<property name="war.dir" value="war" />
	<property name="classesweb.dir" value="WebContent/WEB-INF/classes" />
	<property name="tomcat.dir" value="/home/programmer/tomcat" />
	

	<path id="application-lib">
		<fileset dir="${lib.dir}" includes="**/*.jar" />
	</path>
	
	<path id="tomcat-lib">
		<fileset dir="${tomcat.dir}/lib" includes="**/*.jar" />
	</path>

	<target name="init">
		<echo>init...</echo>
		<delete dir="${classes.dir}" />
		<delete dir="${jar.dir}" />
		<delete dir="${classestest.dir}" />
		<delete dir="${report.dir}" />
		<delete dir="${war.dir}" />
		<delete dir="${classesweb.dir}" />
	</target>

	<target name="compile" depends="init">
		<echo>compile source code</echo>
		<mkdir dir="${classes.dir}" />
		<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}" includes="**/log4j.properties" />
		</copy>
	</target>
	
	<target name="makejar" depends="compile">
		<echo>make jar file</echo>
		<mkdir dir="${jar.dir}" />
		<jar destfile="${jar.dir}/myproject.jar">
			<fileset dir="${classes.dir}">
			</fileset>
		</jar>
    </target>

	<target name="compiletest" depends="compile">
		<echo>compile test source code</echo>
		<mkdir dir="${classestest.dir}" />
		<javac srcdir="${srctest.dir}" destdir="${classestest.dir}" includeantruntime="on" encoding="utf-8">
			<classpath>
				<pathelement location="${classes.dir}" />
				<path refid="application-lib" />
			</classpath>
		</javac>
		<copy todir="${classestest.dir}">
			<fileset dir="${srctest.dir}" includes="**/log4j.properties" />
		</copy>
	</target>

	<target name="junit" depends="compiletest">
		<echo>run junit code</echo>
		<mkdir dir="${report.dir}" />
		<junit printsummary="yes" failureproperty="junit.tests.failure" showoutput="on">
			<classpath>
				<path location="${classes.dir}" />
				<path location="${classestest.dir}" />
				<path refid="application-lib" />
			</classpath>
			<formatter type="xml" />
			<jvmarg value="-Djava.library.path=." />
			<batchtest fork="yes" todir="${report.dir}">
				<fileset dir="${classestest.dir}" includes="**/test/*Test.class" />
			</batchtest>
		</junit>
		<junitreport todir="${report.dir}">
			<fileset dir="${report.dir}">
				<include name="**/TEST-*.xml" />
			</fileset>
			<report todir="${report.dir}" />
		</junitreport>
	</target>
	
	<target name="compileweb" depends="init">
		<echo>compile web source code</echo>
		<mkdir dir="${classesweb.dir}" />
		<javac srcdir="${src.dir}" destdir="${classesweb.dir}" includeantruntime="on" encoding="utf-8">
			<classpath>
				<path refid="tomcat-lib" />
				<path refid="application-lib" />
			</classpath>
		</javac>
		<copy todir="${classesweb.dir}">
			<fileset dir="${src.dir}" includes="**/log4j.properties" />
		</copy>
	</target>
	
	<target name="war" depends="compileweb">  
        <echo>make war file</echo>  
        <mkdir dir="${war.dir}" />  
        <war warfile="${war.dir}/myproject.war" webxml="WebContent/WEB-INF/web.xml">  
            <lib dir="${lib.dir}" />  
            <classes dir="${classesweb.dir}" />  
            <fileset dir="WebContent" />  
        </war>  
    </target>  
	
	<target name="publish" depends="war">  
        <echo>publish war file to tomcat</echo>  
        <copy todir="${tomcat.dir}/webapps">  
            <fileset dir="${war.dir}" includes="myproject.war" />  
        </copy>  
    </target>  

</project>

你可能感兴趣的:(ant,脚本,JUnit,report,include,encoding)