欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ant完整示例

程序员文章站 2022-04-06 11:04:59
...
<?xml version="1.0" encoding="UTF-8"?>
<project name="cloud-ssh2">
	<property file="ant.properties"></property>
	<property name="src.dir" location="src"></property>
	<property name="test.dir" location="test"></property>
	<property name="target.dir" location="target"></property>
	<property name="target.classes" location="${target.dir}/classes"></property>
	<property name="target.test" location="${target.dir}/test"></property>
	<property name="test.output" location="${target.dir}/output"></property>
	<property name="test.output.html" location="${target.dir}/html"></property>
	<property name="web.dir" location="WebContent"></property>
	
	<path id="classpath">
		<fileset dir="D:/Java/dev/eclipse-jee-maven/apache-tomcat-7.0.52/lib">
			<include name="*.jar" />
		</fileset>
		<fileset dir="WebContent/WEB-INF/lib">
			<include name="*.jar" />
		</fileset>
	</path>
	
	<path id="classpath-test">
		<path refid="classpath"></path>
		<pathelement location="${target.classes}"/>
	</path>
	
	<path id="classpath-test-run">
		<path refid="classpath-test"></path>
		<pathelement location="${target.test}"/>
	</path>
	
	<fileset id="test-class" dir="${target.test}">
		<include name="**/*.class"/>
	</fileset>
	
	<target name="show">
		<echo>${datasource.mysql.username}</echo>
		<echo>${datasource.mysql.password}</echo>
		<echo>${datasource.mysql.databaseUrl}</echo>
		<echo>${datasource.mysql.databaseDriver}</echo>
		<echo>----------------------------------</echo>
		<echo>${ant.project.name}</echo>
		<echo>${ant.version}</echo>
		<echo>${ant.file}</echo>
		<echo>${basedir}</echo>
		<echo>${ant.java.version}</echo>
		<echo>${ant.core.lib}</echo>
	</target>
	
	<target name="clean" depends="show">
		<echo>Began to clean up</echo>
		<delete dir="${target.dir}"></delete>
	</target>
	
	<target name="init" depends="clean">
		<echo>Began to mkdir</echo>
		<mkdir dir="${target.dir}"/>
		<mkdir dir="${target.classes}"/>
		<mkdir dir="${target.test}"/>
		<mkdir dir="${test.output}"/>
		<mkdir dir="${test.output.html}"/>
	</target>
	
	<target name="compile" depends="init">
		<echo>Began to compile java src</echo>
		<javac includeantruntime="true" destdir="${target.classes}" srcdir="${src.dir}" classpathref="classpath" />
		
		<echo>Copy resource file to dest dir</echo>
		<copy todir="${target.classes}">
			<fileset dir="${src.dir}">
				<exclude name="**/*.java"/>
			</fileset>
		</copy>
		
		<echo>Began to compile test src</echo>
		<javac includeantruntime="true" destdir="${target.test}" srcdir="${test.dir}" classpathref="classpath-test" />
	</target>
	
	<target name="test" depends="compile">
		<echo>Run junit test</echo>
		<junit printsummary="true">
			<classpath refid="classpath-test-run"></classpath>
			<formatter type="xml"/>
			<batchtest todir="${test.output}">
				<fileset refid="test-class"></fileset>
			</batchtest>
		</junit>	
		<junitreport>
			<fileset dir="${test.output}">
				<include name="*.xml"/>
			</fileset>
			<report format="frames" todir="${test.output.html}"/>
		</junitreport>
	</target>
	
	<target name="war" depends="compile">
		<war destfile="${target.dir}/${ant.project.name}.war" webxml="${web.dir}/WEB-INF/web.xml">
			<fileset dir="${web.dir}" excludes="**/*.jar"></fileset>
			<lib dir="${web.dir}/WEB-INF/lib" ></lib>
			<classes dir="${target.classes}"></classes>
		</war>
	</target>
	
</project>