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.

Creating an Ant Build File for a Stand-alone Application

Listing 20.18 shows the application project build file; you'll notice that it is very similar to the model project build file. It is divided into the same targets: init, clean, delete, prepare, mkdir, compile, package, and all. The application project build file defines the properties differently, but even the property names are almost identical (compare with the model project build file in Listing 20.17).

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

<target name="init" description="initialize the properties."> <property name="local_outdir" value="${outdir}/java_app" /> <property name="build" value="${local_outdir}/classes" /> <property name="lib" value="${outdir}/lib" />
<property name="app_jar" value="${lib}/greetapp.jar" />

</target>
<target name="clean" depends="init"
description="clean up the output directories.">
<delete dir="${build}" />
<delete file="${app_jar}" />
</target>

<target name="prepare" depends="init"
description="prepare the output directory."> <mkdir dir="${build}" />
<mkdir dir="${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>

</classpath>
</javac> </target> <target name="package" depends="compile"
description="package the Java classes into a jar."> <jar jarfile="${app_jar}"
manifest="./META-INF/MANIFEST.MF"
basedir="${build}" />
</target>
<target name="all" depends="clean,package"
description="perform all targets."/>
</project> Listing 20.18