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.

Running an Ant Build File

In this section, we discuss how to run the Hello World model project build file. There are three steps to running this file:

 

1. Set up the environment.

 

2. Go to the directory that contains the build.xml file for the model.

 

3. Run Ant.

 

Successfully running the build script gives us the following output: Buildfile: build.xml
init:
clean:
prepare:
[mkdir] Created dir: C:\tmp\app\model\classes
compile:
[javac] Compiling 3 source files to C:\tmp\app\model\classes
package:
[jar] Building jar: C:\tmp\app\lib\greetmodel.jar
all:
BUILD SUCCESSFUL Total time: 3 seconds

If you do not get this output, check that the properties defined in the init target make sense for your environment. If you are on a Unix platform and the build file is not working, make sure that the /tmp directory exists and that you have the rights to access it. Alternatively, you could run the previous script by entering this on the command line:

$ ant -Doutdir=/usr/rick/tmp/app

Basically, you want to output to a directory that you have access to, just in case you are not the administrator of your own box. If for some reason Ant still does not run, make sure you set up the Ant environment variables.

After you successfully run Ant, the output directory for the model project looks like this:

Root of output directory
\---app
+---lib
| greetmodel.jar
|
\---model
\---classes
\---xptoolkit
\---model
GreetingFactory.class
Greeting.class
GreetingBean.class

Notice that all the intermediate files to build the JAR file are in the model subdirectory. The output from this project is the greetmodel.jar file, which is in ${outdir}/app/lib. The next project, the application project, needs this JAR file in order to compile. In the next section, we discuss how to use Ant to build a stand-alone Java application that uses the JAR file (greetmodel.jar) from the model project.