サンプル
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <project basedir="." default="create.war" name="SampleService"> <property name="tomcat.home" value="../../tomcat/tomcat8"/> <property name="lib.path" value="WebContent/WEB-INF/lib"/> <property name="target" value="1.8"/> <property name="source" value="1.8"/> <path id="tomcat.libraryclasspath"> <fileset dir="${tomcat.home}"> <include name="lib/*.jar"/> </fileset> </path> <path id="webapp.libraryclasspath"> <fileset dir="${lib.path}"> <include name="lib/*.jar"/> </fileset> <pathelement location="WebContent/WEB-INF/classes"/> </path> <path id="SampleService.classpath"> <pathelement location="build/classes"/> <path refid="tomcat.libraryclasspath"/> <path refid="webapp.libraryclasspath"/> </path> <target name="init"> <mkdir dir="build/classes"/> <copy includeemptydirs="false" todir="build/classes"> <fileset dir="src"> <exclude name="**/*.java"/> </fileset> </copy> <copy includeemptydirs="false" todir="build/classes"> <fileset dir="junit"> <exclude name="**/*.java"/> </fileset> </copy> </target> <target name="clean"> <delete dir="build/classes"/> </target> <target depends="init" name="compaile"> <echo message="${ant.project.name}: ${ant.file}"/> <javac destdir="build/classes" includeantruntime="false" source="${source}" target="${target}"> <src path="src"/> <exclude name="junit"/> <classpath> <path refid="SampleService.classpath" /> </classpath> <compilerarg value="-Xlint:unchecked" /> </javac> </target> <target depends="compaile" name="create.war"> <war destfile="${ant.project.name}.war" webxml="WebContent/WEB-INF/web.xml"> <fileset dir="WebContent"> <include name="**/*" /> </fileset> <classes dir="build/classes" excludes="**/*Test.class **/package-info.class" /> </war> </target> </project>
参考文献
WARファイル
https://gist.github.com/1378492/2494e5f4367a77e8cc580ecf3f9cd9862f6c6c83http://www.atmarkit.co.jp/fjava/javatips/109jakarta019.html