Chapter 1. Ant Jumpstart

It is likely that you have already downloaded and installed Ant and are ready to see an example of how it works. If so, then this chapter is for you. Here, we walk through a very basic buildfile example, followed by a full description of Ant’s command-line options. If you prefer to walk through the step-by-step installation procedure first, you might want to skip ahead to Chapter 2 and then come back to this material.

We do not attempt to explain every detail of the buildfile in this chapter. For a more comprehensive example, see Chapter 3.

Files and Directories

For our example, we start with the directory and file structure shown in Figure 1-1. The shaded boxes represent files, and the unshaded boxes represent directories.

Starting point for our example buildfile

Figure 1-1. Starting point for our example buildfile

Tip

You can download this example from this book’s web page, located at http://www.oreilly.com/catalog/anttdg/.

The Ant buildfile, build.xml, exists in the project base directory. This is typical, although you are free to use other filenames or put the buildfile somewhere else. The src directory contains the Java source code organized into an ordinary package structure. For the most part, the content of the source files is not important. However, we want to point out that PersonTest.java is a unit test that will be excluded from the generated JAR file.

Our sample buildfile causes Ant to create the directory tree and files shown inside the shaded, dashed block in Figure 1-2. It also compiles the Java source code, creates oreilly.jar, and provides a “clean” target to remove all generated files and directories.

Directories and files created by our sample buildfile

Figure 1-2. Directories and files created by our sample buildfile

Now let’s look at the buildfile that makes this possible.

Get Ant: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.