Presents your
JAVA E-NEWSLETTER for January 2, 2003
<------------------------------------------->
GET MORE OUT OF ANT WITH THESE USEFUL SNIPPETS
Apache Jakarta's Ant software has fast become a standard for many
development projects, both open source and proprietary. Here are two
simple tips for getting more out of your Ant scripts.
An Ant script is a command you run with a whole set of options, but
there's no obvious way to see those options without looking at the script
itself. Rather than adding a target name that outputs all the options that
may be passed to the script, give each top-level target a description and
use ant-projecthelp. The build.xml snippet would then look like this:
...
...
...
The ant-projecthelp will output this:
Buildfile: build.xml
Default target:
run Run the example
Main targets:
compile Compile the source code
run Run the example
Subtargets:
test
BUILD SUCCESSFUL
Total time: 2 seconds
Anything without a description is automatically considered to be a
sub-target.
A second useful snippet for Ant is the ability to use environment
variables from within your Ant script. Java has moved away from using
environment variables, but for something like an Ant script, they are still
very useful. The Ant developers have made such variables available on common
platforms with the property task's environment attribute. It's used as follows:
The environment attribute turns on environment variables inside the
namespace of "env", allowing any environment variable to be accessed by
prefixing "env." to the variable name.
----------------------------------------