<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>
ant常用功能
最新推荐文章于 2022-08-29 17:51:21 发布