Java Reference
In-Depth Information
name
The name of the target. This is the name entered as an argument to
ant
.
This is also the name that may be used in the
default
attribute of the
project
tag.
unless
This is the reverse of the
if
attribute. The target is built unless the
property is set.
9.4.2.3
There is more than one way to set what we might call variables in
ant
. The
only one we will concern ourselves with here is
properties
. Properties are like a
simple hash, or associative array. They associate value, which is stored as a
String
, with a name, which is also a
String
. They behave very much like the
Properties
class introduced earlier in this topic.
7
You can use buildfile prop-
erties to associate a single name with a single value that you use in multiple
places throughout the buildfile to make configuration changes easier and less
error-prone. Some tasks also expect certain properties to be set, as we shall
soon see.
You set a property with the
property
tag (Example 9.2).
Properties
Example 9.2
A useless
build.xml
example to demonstrate properties
<?xml version="1.0"?>
<project name="pointless" default="useless" basedir=".">
<target name="useless">
<property name="example.utility" value="nil"/>
<echo>This example's usefulness:
${example.utility}. OK?</echo>
</target>
</project>
Running
ant
with Example 9.2 gives this output:
7. In fact, an examination of the
ant
source code reveals that
ant
properties are stored in a
HashTable
.