Section 17.2. Ant Overview


17.2. Ant Overview

Ant was developed in part as an improvement to previous build tools like make. At a high level, the improvements it offers include an improved command file format (using XML as the basis for its buildfiles) and the ability to extend the tool using Java code rather than shell script commands. In the past, many developers found the text format of make and its variants to be somewhat arcane and error-prone (to the point that people developed tools like imake, which provided a metalanguage for the generation of makefiles). An XML format is much more directly accessible to the average developer, the syntax rules are clearer since they are based on general XML syntax, and the plethora of XML tools can be used directly to edit Ant buildfiles.

The ability to extend the build tool using Java code is also an obvious advantage, at least to Java developers. As we'll see later in this section, tasks in Ant are invoked using XML elements in the buildfile with a core set of tasks provided with the tool. Custom Ant tasks can also be written using Java code. This allows for more portable extensibility than earlier shell command systems, since the syntax of shell commands and their arguments tends to be platform-dependent.

Before we look at the model Ant uses for managing development tasks, let's get familiar with the terminology of Ant.

Ant is driven from a buildfile that you write. This buildfile defines a set of project-specific targets that represent specific goals or results that you can request Ant to accomplish. Typical targets might be to compile a set of Java code, to create a jar archive from a set of files, or to check in a set of files to a source control system like CVS, Perforce, or Subversion. Targets can be hierarchical in nature (i.e., one target may depend on the results of other targets, and a target may directly invoke other targets in order to accomplish its goal). A target that generates a jar file may depend on another target that compiles a set of Java files into classes, and it may invoke another target that moves all of the necessary assets into a temporary area before creating the archive.

Ant executes tasks in order to complete specific targets. A task in Ant can be just about any action that you can execute from Java, or the system, or both: compile a Java file, move a file from one directory to another, open a URL and save the contents, and so on. Ant provides a set of core tasks that perform very common operations, like running the Java compiler on a set of Java files, moving files, and deleting files. You can also write your own custom Ant tasks if necessary, as mentioned earlier.

Looking at Ant's build model from the bottom up, it consists of tasks, which are well-defined, general-purpose utilities. A set of core tasks is included natively in Ant, and custom tasks can also be defined if needed. Tasks are strung together to define how various targets are accomplished. A project's targets are defined in a buildfile, which is named build.xml by default, although the file can be named anything you like.



Java Enterprise in a Nutshell
Java Enterprise in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596101422
EAN: 2147483647
Year: 2004
Pages: 269

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net