411 REFERENCE · Wikibooks
Apache Ant/Build File Structure
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Here is the structure of a typical build.xml file:
<?xml version="1.0"?>
Running target init
Running target MyTarget
Here are a few things to note:
The Begin and End tags for project ( and ) MUST start and end the file.
The Begin <project> MUST have an attribute called default which is the name of one of the targets.
Each build file must have at least one target.
The Begin and End tags for and must also match EXACTLY.
Each target MUST have a name.
Targets depend only on other targets and reference them by their target name. Targets NEVER depend on projects or tasks.
Target depends are optional.
Anything between and tags is outputted to the console if the surrounding target is called.
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