Developing Web Applications with Ant
Developing Web Applications with Ant www.triveratech.com
Setting Up Your Environment to Run Ant
If you are running Unix, install Ant in ~/tools/ant; if you are running Windows, install Ant in c:\tools\ant.
You can set up the environment variables in Windows by using Control Panel. However, for your convenience,
we created a Unix shell script (setenv.sh) and a Windows batch file (setenv.bat) that will set up the required
environment variables for you.
Your Unix setenv.sh file should look something like this:
# Setup build environment variables using Bourne shell
Your Windows setenv.bat file should look something like this:
: Setup build environment variables using DOS Batch
Both of these setup files begin by setting JAVA_HOME to specify the location where you installed the
JDK. This setting should reflect your local development environment--make adjustments accordingly. Then, the
files set up the environment variable ANT_HOME, the location where you installed Ant.
The examples in this chapter assume that you have installed Ant in c:\tools\ant on
Windows and in ~/tools/ant on Unix.
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.
Copyright © 2003 Richard Hightower, Trivera Technologies