ant常用功能

<project basedir="." default="build" name="test">
	<property environment="env" />
	<property name="ECLIPSE_HOME" value="D:/eclipse/" />
	<property name="debuglevel" value="source,lines,vars" />
	<property name="target" value="1.7" />
	<property name="source" value="1.7" />

	<property name="lib.dir" value="lib" />
	<property name="src.dir" value="src" />
	<property name="classess.dir" value="bin" />
	<property name="jarname" value="test.jar" />
	<property name="output.dir" value="out" />
	<property name="mainclass" value="org.test.Main" />

	<path id="test.classpath">
		<pathelement location="bin" />
	</path>
	<path id="lib-classpath">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar" />
		</fileset>
	</path>

	<target name="init">
		<mkdir dir="${classess.dir}" />
		<mkdir dir="${output.dir}" />
		<copy includeemptydirs="false" todir="bin">
			<fileset dir="src">
				<exclude name="**/*.java" />
			</fileset>
		</copy>
	</target>
	<target name="clean">
		<delete dir="${classess.dir}" />
		<delete dir="${output.dir}" />
	</target>
	<target depends="clean" name="cleanall" />
	<target name="compile" depends="clean">
		<mkdir dir="${classess.dir}" />
		<javac srcdir="${src.dir}" destdir="${classess.dir}" debug="on">
			<compilerarg line="-encoding UTF-8" />
			<classpath refid="lib-classpath" />
		</javac>
		<copydir src="resources" dest="${classess.dir}" />
	</target>
	<target name="run" depends="compile">
		<java classname="${mainclass}" classpath="${classess.dir}" />
	</target>

	<target name="jar" depends="compile">
		<!-- 复制jar包 -->
		<copy todir="${output.dir}/lib">
			<fileset dir="${lib.dir}" />
		</copy>
		<pathconvert property="mf.classpath" pathsep=" ">
			<mapper>
				<chainedmapper>
					<flattenmapper />
					<globmapper from="*" to="lib/*" />
				</chainedmapper>
			</mapper>
			<path refid="lib-classpath" />
		</pathconvert>
		<jar destfile="${output.dir}/${jarname}" basedir="${classess.dir}">
			<manifest>
				<attribute name="Main-class" value="${mainclass}" />
				<attribute name="Class-Path" value="${mf.classpath}" />
			</manifest>
		</jar>
	</target>

	<target name="war" depends="compile">
		<war destfile="${output.dir}/Root.war" webxml="WebContent/WEB-INF/web.xml">
			<fileset dir="WebContent" includes="**/*.jsp" />
			<lib dir="${lib.dir}" />
			<classes dir="${classess.dir}" />
		</war>
	</target>

	<target depends="build-subprojects,build-project" name="build" />
	<target name="build-subprojects" />
	<target depends="init" name="build-project">
		<echo message="${ant.project.name}: ${ant.file}" />
		<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
			<src path="src" />
			<classpath refid="test.classpath" />
		</javac>
	</target>
	<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects" />
	<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
		<copy todir="${ant.library.dir}">
			<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar" />
		</copy>
		<unzip dest="${ant.library.dir}">
			<patternset includes="jdtCompilerAdapter.jar" />
			<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar" />
		</unzip>
	</target>
	<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
		<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />
		<antcall target="build" />
	</target>
</project>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值