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.

Analysis of the Model Project Build File

Listing 20.17 shows the entire build file for the model project. In this section, we provide a step-by-step analysis of how this build file executes. All the build files in the Hello World example are structured in a similar fashion, so understanding the model project build file is essential to understanding the others. A quick note on naming conventions: As you see from the first line of code in Listing 20.17, the project name for this build file is model. Therefore, we refer to this build file as the model project build file. This naming convention becomes essential once we begin dealing with the five other build files in this project.

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

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

</target>
<target name="clean" depends="init"
description="clean up the output directories and jar.">
<delete dir="${local_outdir}" />
<delete file="${model_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}" />
</target>
<target name="package" depends="compile"
description="package the Java classes into a jar.">
<jar jarfile="${model_jar}" basedir="${build}" /> </target>
<target name="all" depends="clean,package" description="perform all targets."/> </project> Listing 20.17 Let's go over the model project build file and each of its targets in the order they execute. First, the model project sets the all target as the default target: