代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Hello world" default="doc" basedir=".">
<!--properties-->
<propertyname="src.dir"value="src"></property>
<propertyname="report.dir"value="report"></property>
<propertyname="classes.dir"value="classes"></property>
<propertyname="lib.dir"value="lib"></property>
<propertyname="dist.dir"value="dist"></property>
<propertyname="doc.dir"value="doc"></property>
<propertyname="jar.name"value="hello.jar"></property>
<propertyname="war.name"value="hello.war"></property>
<propertyname="WebContent"value="WebContent"></property>
<propertyname="war.dir"value="war"></property>
<!--定义classpath-->
<pathid="master-classpath">
<filesetfile="${lib.dir}/*.jar"/>
<pathelementpath="${classes.dir}"></pathelement>
</path>
<!--初始化任务-->
<targetname="init">
<deletedir="${lib.dir}"></delete>
<deletedir="${dist.dir}"></delete>
<deletedir="${doc.dir}"></delete>
<deletedir="${war.dir}"></delete>
<mkdirdir="${src.dir}"></mkdir>
<mkdirdir="${report.dir}"></mkdir>
<mkdirdir="${classes.dir}"></mkdir>
<mkdirdir="${lib.dir}"></mkdir>
<mkdirdir="${dist.dir}"></mkdir>
<mkdirdir="${doc.dir}"></mkdir>
<mkdirdir="${war.dir}"></mkdir>
<echomessage="初始化完成!"></echo>
</target>
<!--编译-->
<targetname="compile"depends="init"description="compilethesourcefiles">
<javacsrcdir="${src.dir}"destdir="${classes.dir}"includeantruntime="on">
<classpathrefid="master-classpath"></classpath>
</javac>
</target>
<!--打包成jar-->
<targetname="pack"depends="compile"description="make.jarfile">
<jardestfile="${dist.dir}/${jar.name}"basedir="${classes.dir}">
</jar>
</target>
<!--打成war-->
<targetname="war"depends="pack">
<wardestfile="${war.dir}/${war.name}"webxml="${WebContent}/WEB-INF/web.xml">
<filesetdir="${war.dir}"/>
<libdir="${WebContent}/WEB-INF/lib"/>
<classesdir="${classes.dir}"></classes>
</war>
</target>
<!--输出api文档-->
<targetname="doc"depends="war"description="createapidoc">
<javadocdestdir="${doc.dir}"author="ture"version="ture"use="ture"windowtitle="helloworldAPI">
<packagesetdir="${src.dir}"defaultexcludes="yes">
<includename="example/**"/>
</packageset>
<doctitle><![CDATA[<h1>Hello,World</h1>]]></doctitle>
<bottom><![CDATA[<i>AllRightsReserved</i>]]></bottom>
<tagname="todo"scope="all"description="Todo:"/>
</javadoc>
</target>
</project>