我用的开发环境:eclipse 3.1+tomcat 4.1.31。示例Ant 的build.xml如下:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="TradeData" default="TradeData.war">
<!-- properies -->
<property name="user.name" value="xiedd" />
<property name="version" value="1.0.0" />
<property name="src.dir" value="../src" />
<property name="classes.dir" value="../WebRoot/classes" />
<property name="lib.dir" value="../WebRoot/lib" />
<property name="dist.dir" value="../build/release" />
<property name="dist.dir" value="../build/release" />
<property name="war.dir" value="../WebRoot" />
<!-- 定义classpath -->
<path id="master-classpath">
<fileset file="${lib.dir}/*.jar" />
<pathelement path="${classes.dir}" />
</path>
<!-- 初始化任务 -->
<target name="init">
</target>
<!-- 编译 -->
<target name="compile" depends="init" description="compile the source files">
<rmdir dir="${classes.dir}" />
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" target="1.4">
<classpath refid="master-classpath" />
</javac>
</target>
<!-- 测试
<target name="test" depends="compile" description="run junit test">
<mkdir dir="${report.dir}"/>
<junit printsummary="on"
haltonfailure="false"
failureproperty="tests.failed"
showoutput="true">
<classpath refid="master-classpath" />
<formatter type="plain"/>
<batchtest todir="${report.dir}">
<fileset dir="${classes.dir}">
<include name="**/*Test.*"/>
</fileset>
</batchtest>
</junit>
<fail if="tests.failed">
***********************************************************
**** One or more tests failed! Check the output ... ****
***********************************************************
</fail>
</target>
-->
<!-- 打包成war -->
<target name="TradeData.war" description="make .war file">
<mkdir dir="${dist.dir}" />
<war warfile="${dist.dir}/TradeData-${version}.war" webxml="${war.dir}/WEB-INF/web.xml">
<!--<lib dir="${war.dir}/WEB-INF/lib"/>
<classes dir = "${war.dir}/WEB-INF/classes"/>-->
<fileset dir="${war.dir}">
</fileset>
<manifest>
<attribute name="Built-By" value="${user.name}" />
<section name="common">
<attribute name="Implementation-Title" value="apple TradeData.war" />
<attribute name="Implementation-Version" value="${version}" />
<attribute name="Implementation-Vendor" value="apple" />
</section>
</manifest>
</war>
<!--
<jar destfile="${dist.dir}/TradeData-${version}.jar" basedir="${classes.dir}">
<exclude name="**/*Test.*" />
<exclude name="**/Test*.*" />
<manifest>
<attribute name="Built-By" value="${user.name}" />
<section name="common">
<attribute name="Implementation-Title" value="apple" />
<attribute name="Implementation-Version" value="${version}" />
<attribute name="Implementation-Vendor" value="OWASP" />
</section>
</manifest>
</jar>-->
</target>
<!-- 输出api文档 -->
<!--
<target name="doc" depends="pack" description="create api doc">
<mkdir dir="${doc.dir}" />
<javadoc destdir="${doc.dir}" author="true" version="true" use="true" windowtitle="kbase-apidoc">
<packageset dir="${src.dir}" defaultexcludes="yes">
<include name="example/**" />
</packageset>
<doctitle>
<![CDATA[<h1>apple</h1>]]></doctitle>
<bottom>
<![CDATA[Copyright © 2003-2006 apple All Rights Reserved.]]>
</bottom>
<tag name="todo" scope="all" description="To do:" />
</javadoc>
</target>
-->
</project>