ANT Tutorial
Ashley J.S Mills
<ug55axm@cs.bham.ac.uk>
Copyright © 2002 The University Of Birmingham
Table of Contents
1.Introduction ................................................................................................................................................. 1
2.AntInstallation............................................................................................................................................. 1
3.AntBasics ................................................................................................................................................... 1
4. A Typical Project .......................................................................................................................................... 3
5. A Bit About FileSets ..................................................................................................................................... 8
6.AdvancedTopics .......................................................................................................................................... 10
6.1. Flow Of Control ................................................................................................................................. 10
7.References................................................................................................................................................... 13
1. Introduction
Imagine that you are working on a large project. The project is a Java project and consists of many .java files. It consists of
classes that are dependent on other classes and classes which are stubs or drivers, they are situated in multiple directories and the
output files must go into multiple directories too, you have various project build routes for different applications and at the mo-
ment are coordinating all of this manually or using some other build utility which doesn't do what you want it to so many hours are
spent changing directories compiling individual files and so on... Now, imagine if their was a tool that could alleviate the stress
and hassle you are experiencing, OK, enough of the rhetoric, this tool exists, it is called ANT. For a nice definition of what Ant is,
see http://jakarta.apache.org/ant/.
Ant (originally an acronym for Another Neat Tool), is a build tool with special support for the Java programming language but can
be used for just about everything. Ant is platform-independent; it is written purely in Java. Ant is particularly good at automating
complicated repetitive tasks and thus is well suited for automating standardised build processes. Ant accepts instructions in the
form of XML documents thus is extensible and easy to maintain.
2. Ant Installation
The documentation for the installation is written under the assumption that the reader has some experience of installing software
on computers and knows how to change the operating environment of the particular operating system they are using. The docu-
ments entitled Configuring A Windows Working Environment [../winenvars/winenvarshome.html] and Configuring A Unix Work-
ing Environment [../unixenvars/unixenvarshome.html] are of use to people who need to know more.
1. Download the binaries from http://jakarta.apache.org/ant/index.html, unzip them to a suitable directory.
2. Append /path/to/ant/bin to the PATH environment variable.
3. Append the .jar files in /path/to/ant/lib/ to the CLASSPATH environment variable. Set JAVA_HOME to point to the lo-
cation of the JDK installation on the machine that the software is being installed on. Append /path/to/jdk/lib/* to the
CLASSPATH environment variable.
The installation instructions provided with the Ant software installation download are clear enough to warrant abstaining from
writing any more about the installation here. Refer to /path/to/ant/docs/manual/install.html.
3. Ant Basics
An Ant build file comes in the form of an XML document, all that is required is a simple text editor to edit the build file(s). An ed-
itor that provides XML syntax highlighting is preferable. The Ant installation comes with a JAXP-Compliant XML parser, this
means that the installation of an external XML parser is not necessary.
A simple Ant example is shown below followed by a set of instructions indicating how to use Ant. It is recommended that the
reader follow these instructions to gain some experience in using Ant.
1
评论2
最新资源