ANT Tutorial

Structure of a Ant build file

Ant does not define its own custom syntax; instead, its build files are written in XML. There are a defined set of XML elements that Ant understands, and, as you'll see in a later section, new elements can be defined to extend Ant's capabilities. Every build file consists of a single top-level project element, which in turn contains one or more target elements. A target is a defined step in a build that performs any number of operations, such as compiling a set of source files. The operations themselves are performed by other specialized task tags. These tasks are then grouped together into target elements. It is a good practice to split the operations into logical build steps, with each step contained in its own target element. This allows you to perform one individual part of the overall build without necessarily performing other parts. The top-level project element needs to contain a default attribute that specifies the target to be executed if none is specified when Ant is invoked. Then the target itself needs to be defined, using the target element. Below is a simple ant build file:

<?xml version="1.0"?>
<project default="init">
	<target name="init">
	</target>
</project>
Note that this is well-formed XML, with an XML declaration specifying the version of XML being used and with every element being properly closed. It is also possible to open and close an element in one go. So, instead of the separate start and end tags for the target element above, we could have written it as follows:

<target name="init"/>
This more concise form can be clearer when an element doesn't have any enclosed content.