Apache Ant/Build File Structure

Here is the structure of a typical build.xml file:

  Running target init  Running target MyTarget

Here are a few things to note:


 * 1) The Begin and End tags for project ( and ) MUST start and end the file.
 * 2) The Begin MUST have an attribute called default which is the name of one of the targets.
 * 3) Each build file must have at least one target.
 * 4) The Begin and End tags for and must also match EXACTLY.
 * 5) Each target MUST have a name.
 * 6) Targets depend only on other targets and reference them by their target name.  Targets NEVER depend on projects or tasks.
 * 7) Target depends are optional.
 * 8) Anything between and tags is outputted to the console if the surrounding target is called.
 * 9) Every task has to be in a target.

You can execute this from a DOS or UNIX command prompt by creating a file called build.xml and typing:

ant

Ant will search for the build file in the current directory and run the build.xml file.

Here is a sample output of this build:

Buildfile: C:\AntClass\Lab01\build.xml init: [echo] Running target init MyTarget: [echo] Running target MyTarget BUILD SUCCESSFUL Total time: 188 milliseconds

Optionally you can also pass ant the name of the target to run as a command line argument

ant init

Which triggers only the init target

Buildfile: C:\AntClass\Lab01\build.xml init: [echo] Running target init BUILD SUCCESSFUL Total time: 188 milliseconds

Next Chapter