Developing Web Applications With Ant by Richard Hightower - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

The Build File for the Hello World Web Application

This project has many more components than the other subprojects. As you would expect, the Web application project build file (see Listing 20.23) is much more complex, but it builds on the foundation set by the model project--that is, the Web application project build file has the same base targets with the same meanings: init, clean, delete, prepare, mkdir, compile, package, and all.

To the base targets, the Web application project build file adds the prepare_metadata and deploy targets. The prepare_metadata target sets up the Ant filtering for the deployment descriptor. The deploy target adds the ability to deploy to both Tomcat and Resin Web application servers. The remaining details of this build file are covered in the applet and the enterprise beans sections later in this chapter.

<project name="webapplication" default="all" >
<property name="outdir" value="/tmp/app" />

<target name="init" description="initialize the properties."> <property name="local_outdir" value="${outdir}/webapps" /> <property name="lib" value="${outdir}/lib" />
<property name="dist" value="${outdir}/dist" />

<property name="build" value="${local_outdir}/webclasses" /> <property name="meta" value="${local_outdir}/meta" />
<property name="deploy_resin" value="/resin/webapps" /> <property name="deploy_tomcat" value="/tomcat/webapps" />
<property name="build_lib" value="./../lib" /> <property name="jsdk_lib" value="/resin/lib" /> </target>
<target name="clean_deploy" >

<delete file="${deploy_resin}/hello.war" /> <delete dir="${deploy_resin}/hello" /> <delete file="${deploy_tomcat}/hello.war" /> <delete dir="${deploy_tomcat}/hello" />

</target>
<target name="clean" depends="init,clean_deploy" description="clean up the output directories.">
<delete dir="${local_outdir}" />
<delete file="${dist}/hello.war" />
</target>

<target name="prepare" depends="init"
description="prepare the output directory."> <mkdir dir="${build}" />
<mkdir dir="${dist}" />
<mkdir dir="${build_lib}" />

</target>
<target name="compile" depends="prepare"
description="compile the Java source."> <javac srcdir="./src" destdir="${build}">
<classpath >

<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>

<fileset dir="${jsdk_lib}"> <include name="**/*.jar"/>
</fileset>

<fileset dir="${build_lib}"> <include name="**/*.jar"/>
</fileset>

</classpath> </javac>
</target>
<target name="prepare_meta_ejb" if="ejb"> <filter token="Greeting.class"
value="xptoolkit.model.GreetingShadow"/> </target>
<target name="prepare_meta_noejb" unless="ejb"> <filter token="Greeting.class"
value="xptoolkit.model.GreetingBean"/> </target>
<target name="prepare_meta" depends="prepare_meta_ejb, prepare_meta_noejb">

<copy todir="${meta}" filtering="true">
<fileset dir="./meta-data"/>
</copy>
</target>

<target name="package" depends="compile">
<mkdir dir="${meta}" />
<antcall target="prepare_meta" />

<war warfile="${dist}/hello.war" webxml="${meta}/web.xml"> <!-
Include the html and jsp files.
Put the classes from the build into the classes

directory
of the war.

/-->
<fileset dir="./HTML" /> <fileset dir="./JSP" />

<classes dir="${build}" /> <!-- Include the applet. /-->
<fileset dir="${lib}" includes="helloapplet.jar" />

<!-- Include all of the jar files except the ejbeans and applet. The other build files that create jars have to be run in the correct order. This is covered later.

/-->
<lib dir="${lib}" >
<exclude name="greet-ejbs.jar"/>
<exclude name="helloapplet.jar"/>

</lib>
</war>
</target>
<target name="deploy" depends="package">
<copy file="${dist}/hello.war" todir="${deploy_resin}" />
<copy file="${dist}/hello.war" todir="${deploy_tomcat}" />
</target>
<target name="all" depends="clean,package"
description="perform all targets."/> </project> Listing 20.23