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 Hello World master build file.
Analysis of the Master Build File

Notice that the main project build file simply delegates to the application and model subproject and ensures that the subprojects' build files are called in the correct order. For example, when the clean target is executed, the main project build file uses the ant task to call the model project's clean target. Then, the main project calls the application project's clean target using the ant task again, as shown here:

<target name="clean" depends="init"
description="clean up the output directories.">

<ant dir="./Model" target="clean">
<property name="outdir" value="${outdir}" />
</ant>

<ant dir="./Application" target="clean"> <property name="outdir" value="${outdir}" />
</ant>

<delete dir="${outdir}" />
</target>

 

A similar strategy is used with the main project's build target. The build target calls the package target on both the model and application subprojects:

 

<target name="build" depends="prepare"
description="build the model and application modules.">
<ant dir="./model" target="package">
<property name="outdir" value="${outdir}" />
</ant>

<ant dir="./application" target="package"> <property name="outdir" value="${outdir}" />
</ant>

</target>

Thus, we can build both the application and model projects by running the main project. This may not seem like a big deal, but imagine a project with hundreds of subprojects that build thousands of components. Without a build file, such a project could become unmanageable. In fact, a project with just 10 to 20 components can benefit greatly from using nested build files. The master build file orchestrates the correct running order for all the subprojects. We could revisit this main project after we finish each additional subproject and update it. In the next section, we discuss the applet build file.