<project name="test" basedir="." default="onlywar"> <property name="src" location="src" /> <property name="resources" location="resource" /> <property name="web" location="Webroot" /> <property name="lib" location="${web}/WEB-INF/lib" /> <property name="webapps" location="e:/www/test/" /> <path id="core.classpath"> <pathelement location="${src}" /> <fileset dir="${lib}" include="***.jar" /> <!--设置编译包位置,这里我用的是整个tomcat的jar包--> <fileset dir="container_lib" includes="***.jar" /> </path> <target name="clean_old" /> <echo message="delete old" /> <delete dir="${web}/WEB-INF/classes/" /> <mkdir dir="${web}/WEB-INF/classes/" /> <javac destdir="${web}/WEB-INF/classes/" encoding="utf-8" source="1.6" target="1.6" includeantruntime="false"> <src path="${src}"> <src path="${resource}"> <classpath refid="core.classpath"> </javac> <copydir dest="${web}/WEB-INF/classes/" src="${resources}"> </copydir> </target> <target name="onlywar" depends="clean_old" /> <echo message="create new" /> <war destfile="${webapps}/${ant.project.name}.war" webxml="${web}/WEB-INF/web.xml"> <fileset dir="${web}"> <exclude name="**/wa/**"> </fileset> </war> </target> </project>