Developing Web Applications With Ant by Richard Hightower - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Properties, File Sets, and Paths

Ant supports properties, file sets, and paths. Properties are to Ant build scripts as environment variables are to shell scripts and batch files. Properties allow you to define string constants that can be reused. The general rule is that if you use a string literal more than twice, you should probably create a property for it. Later when you need to modify the string constant, if you've defined it as a property you have to change it only once. In Listing 20.2 we've defined two properties: lib and outputdir.

<property name="lib" value="../lib"/>
<property name="outputdir" value="/tmp"/>

...
<path id="myclasspath">
<pathelement path=".;${lib}/log4j.jar"/>
<fileset dir="${lib}">

<include name="**/*.jar"/>
</fileset>
</path>
...

<javac srcdir="./src" destdir="${ outputdir}/classes" > <classpath refid="myclasspath"/>
</javac>

Listing 20.2