Section 1.2. Getting Ant


1.2. Getting Ant

Ant comes in two editions: binary and source. The binary release is ready to use: just download, uncompress, and go. The source release allows you to see what makes Ant run and to make modifications of your own if you choose. To download either, go to http://ant.apache.org/ and click a link under the Download title (either Binary Distributions or Source Distributions).

Downloading a binary edition is easiest: Just click the Binary Distributions link and download the .tar.gz or .zip compressed file.

If you want bleeding-edge Ant, you can get the nightly builds from http://cvs.apache.org/builds/ant/nightly/.


1.2.1. Installing Ant

To install the binary distribution of Ant, expand it. Here's the resulting directory layout (only the bin and lib directories are needed to run Ant):

  ant    |___ bin  Ant launch scripts    |    |___ lib  Ant jars     |    |___ docs Ant documentation    |    |___ etc  XSL for formatting Ant XML output

You need to perform the following steps to complete the setup process:

  1. Add the Ant bin directory to your path.

  2. Set the ANT_HOME environment variable to the directory where you installed Ant.

    On some operating systems, the Ant scripts can guess ANT_HOMEspecifically in Unix and Windows NT/2000but it's better not to rely on them doing so accurately.


  3. Set the JAVA_HOME environment variable to the directory where your JDK is installed.

If you've expanded Ant in c:\ant on Windows, you'll end up with a new directory, c:\ant\apache-ant-1.6.1. If you've installed the JDK in c:\jdk1.4 (and the Java bin directory is C:\jdk1.4\bin), set the environment variables like this:

set ANT_HOME=C:\ant\apache-ant-1.6.1 set JAVA_HOME=C:\jdk1.4  set PATH=%PATH%;%ANT_HOME%\bin

In Unix (bash), assume Ant is installed in /usr/local/ant. Here's how you'd set up the environment:

export ANT_HOME=/usr/local/ant export JAVA_HOME=/usr/local/jdk1.4 export PATH=${PATH}:${ANT_HOME}/bin

In Unix (csh), you'd do something like this:

setenv ANT_HOME /usr/local/ant setenv JAVA_HOME /usr/local/jdk1.4 set path=( $path $ANT_HOME/bin )

There are great instructions on how to set environment variables on many different systems in the installation documentation for the Java JDK.


To compile Java code, you'll need a working JDK on your machine. If you only have a Java Runtime Environment (JRE), Ant won't be able to do many things you need it to do. Also note that the Microsoft JVM/JDK is not supported.

In Windows 95, Windows 98, and Windows ME, the batch file used to launch Ant will not work if ANT_HOME holds a long filename (a filename which is not in the 8.3 format). It's best to install Ant in a short 8.3 path, such as c:\Ant. If you're using one of these operating systems, you'll need to configure more environment space. Update the following line in your config.sys file:

shell=c:\command.com c:\ /p /e:32768


1.2.2. Testing Ant

With Ant in your path, you should be able to run it at the command line. To test this, type ant -version, which should display the current Ant version:

%ant -version Apache Ant version 1.6.1 compiled on February 12 2004

If Ant's not working, you'll see something along these lines:

-bash-2.05b$ ant -bash: ant: command not found

Here's the Windows version of the same error:

C:\>ant 'ant' is not recognized as an internal or external command, operable program or batch file.

In that case, go back over the installation instructions, and look at the Ant documentation for troubleshooting issues.



    Ant. The Definitive Guide
    Ant: The Definitive Guide, 2nd Edition
    ISBN: 0596006098
    EAN: 2147483647
    Year: 2003
    Pages: 115
    Authors: Steve Holzner

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net