Right now the webapp is being built and war'ed in one step. For the simplest application, this is fine, but as we increase complexity, it will be easier to construct the webapp in a directory and then war the entire directory.

to build.properties

dir.build.webapp = ${dir.build}/webapp
dir.build.webapp.webinf = ${dir.build.webapp}/WEB-INF
dir.build.webapp.classes = ${dir.build.webapp.webinf}/classes
dir.build.webapp.lib = ${dir.build.webapp.webinf}/lib

To build.xml

    <!-- ==========================================================
       
             webapp
             assemble web application
       
         ========================================================== -->    
    <target name="webapp" depends="compile">
           
        <echo level="info">
    ***********************************************************************
    *
    * Assembling webapp ${webapp.name} to ${dir.build.webapp}
    *
    ***********************************************************************
        </echo>            

        <delete dir="${dir.build.webapp}"/>
        <mkdir dir="${dir.build.webapp}"/>
        <mkdir dir="${dir.build.webapp.webinf}"/>
        <mkdir dir="${dir.build.webapp.classes}"/>
        <mkdir dir="${dir.build.webapp.lib}"/>
       
        <!-- copy classes -->
        <copy todir="${dir.build.webapp.classes}">
            <fileset dir="${dir.build.source}">
                <include name="**/*"/>
            </fileset>
        </copy>

        <!-- copy config files to root directory -->
        <copy todir="${dir.build.webapp}">
            <fileset dir="${basedir}">
                <include name="*.*"/>
                <exclude name="build.*"/>
                <exclude name=".*"/>
            </fileset>
        </copy>
       
        <!-- copy dependencies -->
        <copy todir="${dir.build.webapp.lib}">
            <fileset dir="${dir.lib}">
                <include name="**/*.jar"/>
            </fileset>
        </copy>
       
        <!-- copy jsp's -->
        <copy todir="${dir.build.webapp.webinf}">
            <fileset dir="${dir.jsp.source}">
                <include name="**/*.jsp"/>
            </fileset>
        </copy>
    </target>

    <!-- ==========================================================
       
             war
             create a war file from classes, libraries, config files,
             and other components
       
         ========================================================== -->    
    <!--
    <target name="war" depends="compile" description="create a deployable war file">
    -->
    <target name="war" depends="webapp" description="create a deployable war file">
        <echo level="info">
    ***********************************************************************
    *
    * Creating deployable webapp ${webapp.name}
    *
    ***********************************************************************
        </echo>    
       
        <!-- include all files except metadata (which will be specifically listed
             and hidden files -->
        <!--
        <fileset id="war.fileset" dir="${dir.jsp.source}">
            <exclude name="metadata/**"/>
            <exclude name=".*/**"/>
            <exclude name="**/web.xml"/>
        </fileset>
        -->
        <delete dir="${dir.build.war}"/>
        <mkdir dir="${dir.build.war}"/>
        <!--
        <war destfile="${dir.build.war}/${webapp.name}" webxml="${webapp.webxml.file}">
            <fileset refid="war.fileset"/>
            <lib dir="${dir.lib}"/>
            <classes dir="${dir.build.source}"/>
           
        </war>
        -->
        <war destfile="${dir.build.war}/${webapp.name}"
             webxml="${webapp.webxml.file}"
             basedir="${dir.build.webapp}"
             compress="yes"
             level="9">
        </war>
    </target>

Now test it out

> ant war

Now undeploy the JP project in Tomcat and deploy the new war. Hopefully you won't notice any differences (other than this one being slightly compressed for upload speed. uncompressed: 1,403,432 comp L9: 1,280,893 (9% compression) If everything worked, remove the comments from the war target

    <target name="war" depends="webapp" description="create a deployable war file">
        <echo level="info">
    ***********************************************************************
    *
    * Creating deployable webapp ${webapp.name}
    *
    ***********************************************************************
        </echo>    
       
        <delete dir="${dir.build.war}"/>
        <mkdir dir="${dir.build.war}"/>

        <war destfile="${dir.build.war}/${webapp.name}"
             webxml="${webapp.webxml.file}"
             basedir="${dir.build.webapp}"
             compress="yes"
             level="9">
        </war>
    </target>

test again

> ant war

Now we'll add the war file to the 'zip' target. Start with adding this property to the build.properties file

dir.deploy.temp.war = ${dir.deploy.temp}/war

Now in build.xml

    <target name="zip" depends="init,junit,javadoc,jar,war" description="Create zip file">
        [...]
        <mkdir dir="${dir.deploy.temp.jar}"/>
        <mkdir dir="${dir.deploy.temp.war}"/>
        [...]      
        <!-- copy war file -->
        <copy todir="${dir.deploy.temp.war}">
            <fileset dir="${dir.build.war}">
                <include name="**/*"/>
            </fileset>
        </copy>
    </target>

Now test to see that everything is working

> ant svn zip

Check JP/deploy and open the zip file. You should see doc, jar, and war directories.

> svn inc.build.minor

commit