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.

What Does an Ant Build File Look Like?

Ant, which is XML based, looks a little like HTML. It has special tags called tasks, which give instructions to the Ant system. These instructions tell Ant how to manage files, compile files, jar files, create Web application archive files, and much more.

Listing 20.1 shows a simple Ant build file with two targets. Ant build scripts have a root element called project. The project element consists of subelements called targets. These elements in turn have task elements. Task elements do useful things, such as creating directories and compiling Java source into Java classes. All of the tasks for a given target are executed when the target is scheduled to execute. The project element has a default attribute, which specifies the target that should be executed for the project. In Listing 20.1, the compile target is the default. However, the compile target has a dependency specified by the depends attribute. The depends attribute can specify a comma-delimited list of dependencies for a target.

<project name="hello" default="compile"> <target name="prepare">
<mkdir dir="/tmp/classes" /> </target>

<target name="compile" depends="prepare"> <javac srcdir="./src" destdir="/tmp/classes" />
</target>

</project> Listing 20.1