【Ant】 WAR ファイルの作成

はじめに

 * テストコードを除外したWARファイルを作成する

サンプル

<?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>


関連記事

【Ant】 Javaコンパイル / WAR ファイルの作成

https://blogs.yahoo.co.jp/dk521123/34019895.html

【Ant】 JARファイルの作成

https://blogs.yahoo.co.jp/dk521123/36874223.html