The build.xml file is to Ant what a makefile is to make.
Althoug build.xml is an
xml file, there is no
dtd nor a
schema to validate it! The document, however, must be
well formed.
Ant can be instructed to use a differently named build.xml file by using the
-f option.
Sample build.xml
Tags
A build.xml file can contain the following tags:
project
It can contain the following attributes:
name
This attribute names the project.
default
This attribute specifies the default target. That is, the target to be run if none is specified on the command line.
basedir
This attribute specifies the base directory that is used to construct absolute paths from relative paths.
basedir behaves like a property: it can be overriden on the command line:
target
A target names a set of tasks that are executed when this target is run. A default target can be specified with the
default attribute in the
project element.
The following attributes can be specified:
name
Specifies the name of this target. In order to invoke a target, use this name on the command line:
This attribute is required.
default
???
if
The name of a property that must be set in order for a target to be executed. Consider the following file:
target_if
Just anting it:
prints
Buildfile: target_if.xml
print_something:
BUILD SUCCESSFUL
Total time: 0 seconds
If, however, the
property print_it is set:
ant -f target_if.xml -Dprint_it=1
Buildfile: target_if.xml
print_something:
[echo] print_it was set
BUILD SUCCESSFUL
Total time: 0 seconds
depends
Lists (comma seperated) all targets on which this target depends. That is, it first makes all other targets (if necessary) before it makes this target.
description
????
javac
Invokes the java compiler (
javac).
The following attributes can be specified:
srcdir
destdir
debug
deprecation
optimize
classpath
The following attributes can be specified:
refid
property
file
name
value
path
id
pathelement
location
fileset
dir
copy
todir
mkdir
dir
echo
Prints a message to the console.
message
Specifies the message to be printed.
echo.xml
<project default="print_something">
<target name="print_something">
<echo message="Here's a secret message" />
</target>
</project>
If this file (named echo.xml) is invoked with Ant, it prints:
Buildfile: echo.xml
print_something:
[echo] Here's a secret message
BUILD SUCCESSFUL
Total time: 0 seconds
A property's value can be echoed by placing like so:
echo_property.xml
Now, ant'ing this file:
Buildfile: echo_property.xml
print_something:
[echo] The value of foo is bar
BUILD SUCCESSFUL
Total time: 0 seconds
echo_property.xml can be used to demonstrate the effect of
ant's -D option:
ant -f echo_property.xml -Dfoo="overriding bar's default"
Buildfile: echo_property.xml
print_something:
[echo] The value of foo is overriding bar's default
BUILD SUCCESSFUL
Total time: 0 seconds
javadoc
The following attributes can be specified:
sourcepath
destdir
packagenames
taskdef
name
????
classname
????