<!--build.xml--> <?xml version="1.0" encoding="utf-8" ?> <project default="second"> <description> </description> <!--在当前目录下常见一个叫helloworld的文件夹--> <target name="init" description=""> <mkdir dir="helloworld"/> <mkdir dir="helloworld2"> </target> <target name="second" depends="init"> <delete dir="helloworld"/> <delete dir="helloworld2"> </target> <target name="myCompile" depends="preprocess"> <javac srcdir="src" destdir="${compile}"></javac> </target> <target name="dist" depends="myCompile"> <tstamp></tstamp> <jar destfile="${dist}/package-${DSTAMP}.jar" basedir="${compile}"> <manifest> <attribute name="Built-By" value="$user.name"/> <attribute name="Main-Class" value="ant.Test"> </manifest> </jar> </target> <!--删除单个文件--> <target name="deleteFile"> <delete file="${dist}/package.jar"></delete> </target> <!--复制和移动文件及目录--> <copy file="src/Test.java" tofile="src/TestCopy.java"> <move file="src/Test.java" tofile="src/TestCopy.java"> </project> <!-- Ant 没有定义它自己的自定义语法;相反它的生成文件是用XML编写的。存在一组Ant能够理解的预定义XML元素,而且还可以自定义新的元素来扩展Ant的功能。每个生成文件由单个project元素组成,该元素有包含一个或多个target元素。一个目标是生成过程中已定义的一个步骤,它执行任意数量的操作,比如编译一组源文件。并且这些操作本生是有其他任务标签执行的。 指定build文件:ant -f helloworld.xml -->