Installing Ant

Getting Ant

Binary Edition

The latest stable version of Ant is available from the Ant web page http://jakarta.apache.org/ant/. If you like living on the edge, you can download the latest version from http://jakarta.apache.org/builds/ant/nightly/.

Source Edition

If you prefer the source edition, you can download the source for the latest Ant release from http://jakarta.apache.org/builds/ant/release/v1.5/src/. Again, if you prefer the edge, you can access the code as it is being developed via CVS. The Jakarta website has details on accessing CVS. Please checkout the jakarta-ant module. See the section Building Ant on how to build Ant from the source code. You can also access the Ant CVS repository on-line.


System Requirements

Ant has been used successfully on many platforms, including Linux, commercial flavours of Unix such as Solaris and HP-UX, Windows 9x and NT, Novell Netware 6 and MacOS X.

To build and use Ant, you must have a JAXP-compliant XML parser installed and available on your classpath.

The binary distribution of Ant includes the latest version of the Apache Xerces2 XML parser. Please see http://java.sun.com/xml/ for more information about JAXP. If you wish to use a different JAXP-compliant parser, you should remove xercesImpl.jar and xmlParserAPIs.jar from Ant's lib directory. You can then either put the jars from your preferred parser into Ant's lib directory or put the jars on the system classpath.

For the current version of Ant, you will also need a JDK installed on your system, version 1.1 or later. Some tasks work better on post-1.1 systems; some tasks only work on Java 1.2 and successors. A future version of Ant -Ant 2.0- will require JDK 1.2 or later, though Ant 1.x strives to retain 1.1 compatibility.

Note: The Microsoft JVM/JDK is not adequate on its own, although the MS compiler is supported.

Note #2: If a JDK is not present, only the JRE runtime, then many tasks will not work.


Installing Ant

The binary distribution of Ant consists of the following directory layout:

  ant
   +--- bin  // contains launcher scripts
   |
   +--- lib  // contains Ant jars plus necessary dependencies
   |
   +--- docs // contains documentation
   |      +--- ant2    // a brief description of ant2 requirements
   |      |
   |      +--- images  // various logos for html documentation
   |      |
   |      +--- manual  // Ant documentation (a must read ;-)
   |
   +--- etc // contains xsl goodies to:
            //   - create an enhanced report from xml output of various tasks.
            //   - migrate your build files and get rid of 'deprecated' warning
            //   - ... and more ;-)
Only the bin and lib directories are required to run Ant. To install Ant, choose a directory and copy the distribution file there. This directory will be known as ANT_HOME.

Windows 95 and Windows 98 Note:
  On these systems, the script used to launch Ant will have problems if ANT_HOME is a long filename. This is due to limitations in the OS's handling of the "for" batch-file statement. It is recommended, therefore, that Ant be installed in a short path, such as C:\Ant.

Before you can run ant there is some additional set up you will need to do:

Note: Do not install Ant's ant.jar file into the lib/ext directory of the JDK/JRE. Ant is an application, whilst the extension directory is intended for JDK extensions. In particular there are security restrictions on the classes which may be loaded by an extension.

Optional Tasks

Ant supports a number of optional tasks. An optional task is a task which typically requires an external library to function. The optional tasks are packaged together with the core Ant tasks.

The external libraries required by each of the optional tasks is detailed in the Library Dependencies section. These external libraries may either be placed in Ant's lib directory, where they will be picked up automatically, or made available on the system CLASSPATH environment variable.

Windows

Assume Ant is installed in c:\ant\. The following sets up the environment:

set ANT_HOME=c:\ant
set JAVA_HOME=c:\jdk1.2.2
set PATH=%PATH%;%ANT_HOME%\bin

Unix (bash)

Assume Ant is installed in /usr/local/ant. The following sets up the environment:

export ANT_HOME=/usr/local/ant
export JAVA_HOME=/usr/local/jdk-1.2.2
export PATH=${PATH}:${ANT_HOME}/bin

Unix (csh)

setenv ANT_HOME /usr/local/ant
setenv JAVA_HOME /usr/local/jdk-1.2.2
set path=( $path $ANT_HOME/bin )

Advanced

There are lots of variants that can be used to run Ant. What you need is at least the following:

The supplied ant shell scripts all support an ANT_OPTS environment variable which can be used to supply extra options to ant. Some of the scripts also read in an extra script stored in the users home directory, which can be used to set such options. Look at the source for your platform's invocation script for details.

Building Ant

To build Ant from source, you can either install the Ant source distribution or checkout the jakarta-ant module from CVS.

Once you have installed the source, change into the installation directory.

Set the JAVA_HOME environment variable to the directory where the JDK is installed. See Installing Ant for examples on how to do this for your operating system.

Make sure you have downloaded any auxiliary jars required to build tasks you are interested in. These should either be available on the CLASSPATH or added to the lib directory. See Library Dependencies for a list of jar requirements for various features. Note that this will make the auxiliary jars available for the building of Ant only. For running Ant you will still need to make the jars available as described under Installing Ant.

Your are now ready to build Ant:

build -Ddist.dir=<directory_to_contain_Ant_distribution> dist    (Windows)

build.sh -Ddist.dir=<directory_to_contain_Ant_distribution> dist    (Unix)

This will create a binary distribution of Ant in the directory you specified.

The above action does the following:

On most occasions you will not need to explicitly bootstrap Ant since the build scripts do that for you. If however, the build file you are using makes use of features not yet compiled into the bootstrapped Ant, you will need to manually bootstrap. Run bootstrap.bat (Windows) or bootstrap.sh (UNIX) to build a new bootstrap version of Ant.

If you wish to install the build into the current ANT_HOME directory, you can use:

build install    (Windows)

build.sh install    (Unix)

You can avoid the lengthy Javadoc step, if desired, with:

build install-lite    (Windows)

build.sh install-lite    (Unix)

This will only install the bin and lib directories.

Both the install and install-lite targets will overwrite the current Ant version in ANT_HOME.


Library Dependencies

The following libraries are needed in your CLASSPATH or in the install directory's lib directory if you are using the indicated feature. Note that only one of the regexp libraries is needed for use with the mappers. You will also need to install the Ant optional jar containing the task definitions to make these tasks available. Please refer to the Installing Ant / Optional Tasks section above.

Jar Name Needed For Available At
An XSL transformer like Xalan or XSL:P style task http://xml.apache.org/xalan-j/index.html for Xalan.
XSL:P used to live at http://www.clc-marketing.com/xslp/, but the link doesn't work any longer and we are not aware of a replacement site.
jakarta-regexp-1.2.jar regexp type with mappers jakarta.apache.org/regexp/
jakarta-oro-2.0.4.jar regexp type with mappers and the perforce tasks jakarta.apache.org/oro/
junit.jar junit tasks www.junit.org
xalan.jar junitreport task xml.apache.org
stylebook.jar stylebook task CVS repository of xml.apache.org
testlet.jar test task java.apache.org/framework
antlr.jar antlr task www.antlr.org
bsf.jar script task oss.software.ibm.com/developerworks/projects/bsf
netrexx.jar netrexx task www2.hursley.ibm.com/netrexx
js.jar javascript with script task www.mozilla.org/rhino
jpython.jar python with script task www.jpython.org
jacl.jar and tcljava.jar TCL with script task www.scriptics.com/java
BeanShell JAR(s) BeanShell with script task www.beanshell.org
netcomponents.jar ftp and telnet tasks www.savarese.org/oro/downloads
bcel.jar classfileset data type, JavaClassHelper used by the ClassConstants filter reader and optionally used by ejbjar for dependency determination jakarta.apache.org/bcel/
mail.jar Mail task with Mime encoding, and the MimeMail task http://java.sun.com/products/javamail/
activation.jar Mail task with Mime encoding, and the MimeMail task http://java.sun.com/products/javabeans/glasgow/jaf.html
jdepend.jar jdepend task http://www.clarkware.com/software/JDepend.html


Copyright © 2000-2002 Apache Software Foundation. All rights Reserved.