Java Reference
In-Depth Information
Installing Ant on UNIX (Bash)
To install Ant on UNIX (or Linux), follow these steps:
1 Untar the Ant tarball to a local directory (for example, /opt/ant). In this direc-
tory, tar creates a subdirectory for the Ant distribution, for example, /opt/
ant/apache-ant-1.7.1.
2 Add this directory to your environment as ANT_HOME , for example:
export ANT_HOME=/opt/ant/apache-ant-1.8.0
3 Add the ANT_HOME/bin folder to your system's command path:
export PATH=${PATH}:${ANT_HOME}/bin
4 We recommend that you specify the location of your JDK as the JAVA_HOME
environment variable:
export JAVA_HOME=/usr/java/jdk1.6.0_14/
5 To enable Ant's JUnit task, copy the file junit.jar to the ${ANT_HOME}/lib
folder. Ant will add the JAR file to the classpath for your build. We look at
other options later.
9.4
Ant targets, projects, properties, and tasks
When you build a project, you often want to produce more than binary code. For a
distribution, you may also want to generate Javadocs. For an internal development
build, you might skip Javadoc generation. At times, you may want to run a build from
scratch. You may also want to compile only the classes that have changed. To help you
manage the build process, a build file may have several targets, encapsulating the dif-
ferent tasks needed to create your application and related resources.
To make the build files easier to configure and reuse, Ant lets you define property
elements (similar to a constant in programming, or a final field in Java). The core Ant
concepts are as follows:
Build file —Each build file is usually associated with a particular development
project. Ant uses the project XML tag as the root element in a build file to
define the project. It also lets you specify a default target, so you can run Ant
without any parameters.
Target —When you run Ant, you can specify one or more targets to execute.
Targets can optionally declare dependencies on other targets. If you ask Ant to
run one target, Ant will execute its dependent targets first . This lets you cre-
ate, for example, a distribution target that depends on other targets, like
clean , compile , javadoc , and war .
Property elements —Because many of the targets within a project share the same
settings, Ant lets you create property elements to encapsulate specific settings
and reuse them throughout a build file. To refer to a property in a build file,
you use the notation ${property} . To refer to the property named target.dir ,
you'd write ${target.dir} .
 
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search