Using Property Files
In larger build files, you might be working with dozens of properties, and storing them in property files is common. Setting tens, or hundreds, of properties all within a build file is a bad habit to get into and almost impossible to maintain.
Using property files means that you can quickly tailor a build file to different sets of circumstances by swapping property files. And you can store property values; though we've been using mostly true/false properties to make conditional processing easier, they can hold all kinds of textual data, such as copyright notices and legal information, in a central repository everyone can share.
Tip
You can specify a property file to use on the command line with
the -propertyfile option.
Take a look at Example
2-2, which uses a property file to hold a property named message. This example points to the property
file with the property task's
file attribute, which can hold the
fully qualified name of the file. You can use the property task's url attribute to point to a property
file.
Example 2-2. Using a property file (ch02/properties/build.xml)
<?xml version="1.0" ?> <project default="main"> <property file="build.properties" /> <property name="src" location="source" /> <property name="output" location="bin" /> <target name="main" depends="init, compile, compress"> <echo> ${message} </echo> </target> <target name="init"> <mkdir dir="${output}" /> </target> <target name="compile"> <javac srcdir="${src}" destdir="${output}" /> </target> ...