Java Reference
In-Depth Information
At the top of the file a series of properties are set, including the locations of various direct-
ories. Note that one property can refer to another by using the
${...}
syntax.
A series of
<task>
elements (
clean
,
compile
,
jar
,
run
,
clean-compile
, and
main
) are defined to represent individual actions during the build process. Some tasks de-
pend on others, which is expressed using the
depends
attribute of the
<task>
element.
All the defined tasks ultimately delegate to a library of predefined Ant tasks. Here those
tasksincludefile-basedtaskslike
mkdir
and
delete
,andJava-relatedtaskslike
javac
,
jar
, and
java
.
Executing this build without arguments means typing
ant
at the command line, which will
execute the default
main
task. Because
main
depends on
clean
and
run
it will execute
those tasks first, which will execute their own individual dependencies, and so on. The res-
ult looks like the following listing.
Listing 5.2. Execution of the default task in the “Hello, World” Ant build
Buildfile: /.../build.xml
clean:
[delete] Deleting directory /.../build
compile:
[mkdir] Created dir: /.../build/classes
[javac] Compiling 1 source file to /.../build/classes
jar:
[mkdir] Created dir: /.../build/jar
[jar] Building jar: /.../build/jar/HelloWorld.jar
run:
[java] Hello, World!
main:
BUILD SUCCESSFUL
Total time: 1 second
Each task outputs its own name, followed by the included built-in Ant tasks indented un-
derneath. The build completed successfully, though that can be misleading. The
BUILD
SUCCESSFUL
statement at the end means that Ant finished all the tasks. The individual
tasks may or may not have worked.
The tasks chosen here are typical, but there is no standard. Each organization (and even
each developer) is free to choose their own. Reusing tasks between different builds also re-