Ant有一个配置文件build.xml,所有的命令编写都放在这个xml文件中进行
一个build.xml文件的内容如下:
<project name="my-project" default="dist" basedir="."> <description> simple example build file </description> <!-- set global properties for this build --> <property name="src" location="src/main/java"/> <property name="build" location="target/classes"/> <property name="dist" location="target"/> <property name="webApp" value="E:\apache-tomcat-5.5.26\webapps\ant-project"/>
<target name="init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <mkdir dir="org.apache.maven.model.Build@d7e661"/> </target>
<target name="compile" depends="init" description="compile the source " > <javac srcdir="${src}" destdir="org.apache.maven.model.Build@d7e661"/> </target>
<target name="dist" depends="compile" description="generate the distribution" > <!-- Create the distribution directory --> <mkdir dir="${dist}/lib"/> <copy todir="${webApp}" overwrite="true"> <fileset dir="${basedir}/WebRoot" excludes="**/*.class"/> </copy> <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir= “org.aaxx.xxfd.xxx” </target>
<target name="clean" description="clean up" > <delete dir="org.apache.maven.model.Build@d7e661"/> <delete dir="${dist}"/> </target> </project> |
在这个简单的 Ant 例子中,你能看到,你需要明确的告诉 Ant 你想让它做什么。有
一个包含 javac 任务的编译目标用来将 src/main/java 的源码编译至 target/classes
目录。你必须明确告诉 Ant 你的源码在哪里,结果字节码你想存储在哪里,如何将这些字节码打包成 JAR 文件。虽然最近有些进展以帮助 Ant 减少程序,但一个开发者对
Ant 的感受是用 XML 编写程序语言。
Build.xml配置文件详细解释
下面简单的解释下这个文件 |
参考文献:1,《Maven权威指南》,见Maven与Ant对比一节
2,http://www.javaeye.com/topic/319186