只要改改就可以用了
<?xml version="1.0" encoding="UTF-8"?> <!-- name:对应工程的名字;default:需要的缺省任务(运行"ant"不指明任务时执行的任务) --> <project name="drpt" default="dist" basedir="."> <!-- 建立目录结构 src JAVA源码编辑目录 lib jar包(类库)存放目录 bin 编译生成的class文件存放目录 dist war和javadoc存放目录 WebRoot jsp文件存放地方 config 配置文件存放地方 --> <property name="appName" value="drpt"/> <property name="src.dir" value="src"/> <property name="lib.dir" value="WebContent/WEB-INF/lib"/> <property name="dist.dir" value="dist"/> <property name="classes.dir" value="WebContent/WEB-INF/classes"/> <property name="webapps.dir" value="C:/Tomcat6/webapps"/> <property name="webroot.dir" value="WebContent"/> <property name="test.dir" value="test" /> <property name="online.dir" value="online" /> <!-- Compilation Classpath 路径设置 --> <path id="compile.classpath"> <pathelement location="${classes.dir}"/> <fileset dir="${lib.dir}" includes="**/*.jar" /> </path> <!-- Clean Target 删除先前的目录结构 --> <target name="clean" description="Delete old build and dist directories"> <delete dir="${classes.dir}"/> <delete dir="${dist.dir}/*.war"/> </target> <!-- Prepare Target 建立打包的目的目录结构 --> <target name="prepare" depends="clean"> <mkdir dir="${classes.dir}"/> <mkdir dir="${dist.dir}"/> </target> <!-- Compile Target 编译代码,在这之前先由prepare建立目录结构 --> <target name="compile" depends="prepare" description="Compile java sources"> <!-- Compile java class as necessary --> <javac srcdir="${src.dir}" destdir="${classes.dir}" encoding="utf-8" debug="true" debuglevel="source,lines,vars" includeantruntime="on"> <classpath refid="compile.classpath"/> </javac> </target> <!-- Dist Target 将应用打包成线上环境使用的war--> <target name="dist" depends="compile" description="create war file for the fomal envionment"> <delete file="${classes.dir}/*.xml"/> <delete file="${classes.dir}/*.properties"/> <copy todir="${classes.dir}"> <fileset dir="${online.dir}"> <exclude name="*.svn"/> <include name="**/*.xml"/> <include name="**/*.properties" /> </fileset> </copy> <jar jarfile="${dist.dir}/${appName}.war" basedir="${webroot.dir}"/> </target> <target name="test" description="create war file for test envionment 10.5.22.99"> <delete dir="${classes.dir}"/> <delete file="${test.dir}/*.war"/> <mkdir dir="${classes.dir}"/> <javac srcdir="${src.dir}" destdir="${classes.dir}" encoding="utf-8" debug="true" debuglevel="source,lines,vars" includeantruntime="on"> <classpath refid="compile.classpath"/> </javac> <delete file="${classes.dir}/*.xml"/> <delete file="${classes.dir}/*.properties"/> <copy todir="${classes.dir}"> <fileset dir="${test.dir}"> <exclude name="*.svn"/> <exclude name="*.war"/> <include name="**/*.xml"/> <include name="**/*.properties" /> </fileset> </copy> <jar jarfile="${test.dir}/${appName}.war" basedir="${webroot.dir}"/> </target> <target name="testdeploy" description="deploy test war to local tomcat"> <delete dir="${webapps.dir}/${appName}.war"/> <delete dir="${webapps.dir}/${appName}"/> <delete dir="${classes.dir}"/> <mkdir dir="${classes.dir}"/> <copy todir="${classes.dir}"> <fileset dir="${test.dir}"> <exclude name="*.svn"/> <exclude name="*.war"/> <include name="**/*.xml"/> <include name="**/*.properties" /> </fileset> </copy> <javac srcdir="${src.dir}" destdir="${classes.dir}" encoding="utf-8" debug="true" debuglevel="source,lines,vars"> <classpath refid="compile.classpath"/> </javac> <jar jarfile="${webapps.dir}/${appName}.war" basedir="${webroot.dir}"/> </target> </project>