Ant: Installation

As I have worked on Ant before sometime for a project and I had few of my own documents for reference, related to installing and using Apache Ant. I thought of sharing those via this blog as it might be useful to someone out there, or at-least would be a backup of my doc in the Blogger servers. 😉

In this series of Ant, I put and introductory post which is followed by a Hello World post, and then I got a couple of IMs asking how could one come to Hello World before an installation post. (Seems thats the standard way of tutorial, so I said I’m not writing any tutorials, but thought of posting this now… 🙂 … ).

System Requirements for Ant

Ant has been used successfully on many platforms, including Linux, MacOS X, Windows XP and Unix. To build and use Ant, you must have a JAXP-compliant XML parser installed and available on your classpath, such as Xerces.

Note: I did this installation on a HP server running Red Hat Enterprise Linux WS Version 4 Update 4.

For the current version of Ant, you will also need a JDK installed on your system, version 1.2 or later required, 1.5 or later strongly recommended. The later the version of Java, the more Ant tasks you get.

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

Building Ant

Obtaining Ant

To build Ant from source, you can either install the Ant source distribution or checkout the Ant module from SVN. I obtained the Ant source version and placed it at /opt/

Once you have obtained the source, change into the installation directory and run,

[root@nimal opt]# tar -xzvf apache-ant-1.7.0-src.tar.gz

This will creat 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.

Note: The bootstrap process of Ant requires a greedy compiler like Sun’s javac or jikes. It does not work with gcj or kjc.

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

In our case we need the JUnit jar.

Environment Settings

Linux/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/java/jdk1.6.0/ export PATH=${PATH}:${ANT_HOME}/bin

The above can be set by editing the .bashrc file.

[root@nimal ~]# vi ~/.

Once this file is opened it will look like this.

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

Append these lines below the end of the if clause below fi

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

And the final file should look like this; save and close the file.

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

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

Normal build and install

Your are now ready to build Ant:

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

[root@nimal opt]# cd /opt/apache-ant-1.7.0/
[root@nimal apache-ant-1.7.0]# sh build.sh -Ddist.dir=/usr/local/ant/ dist
Buildfile: build.xml

dist:

prepare:

check_for_optional_packages:

build:
[copy] Copying 2 files to /opt/apache-ant-1.7.0/build/classes

jars:
[jar] Building jar: /opt/apache-ant-1.7.0/build/lib/ant.jar

.
.
.

compile-tests:

test-jar:

dist-lite:
[mkdir] Created dir: /usr/local/ant
[mkdir] Created dir: /usr/local/ant/bin
[mkdir] Created dir: /usr/local/ant/lib
[copy] Copying 8 files to /usr/local/ant/lib
[copy] Copying 2 files to /usr/local/ant/lib
[copy] Copying 13 files to /usr/local/ant/bin

javadoc_check:

javadocs:
[mkdir] Created dir: /opt/apache-ant-1.7.0/build/javadocs
[javadoc] Generating Javadoc

.
.
.

[javadoc] 114 warnings

dist_javadocs:
[mkdir] Created dir: /usr/local/ant/docs/manual/api
[copy] Copying 1180 files to /usr/local/ant/docs/manual/api

internal_dist:
[mkdir] Created dir: /usr/local/ant/etc
[copy] Copying 1 file to /usr/local/ant/lib
[copy] Copying 1 file to /usr/local/ant/lib
[copy] Copying 25 files to /usr/local/ant/lib
[copy] Copying 1 file to /usr/local/ant/lib
[copy] Copying 259 files to /usr/local/ant/docs
[copy] Copying 33 files to /usr/local/ant/docs
[copy] Copying 11 files to /usr/local/ant
[copy] Copying 15 files to /usr/local/ant/etc

BUILD SUCCESSFUL
Total time: 59 seconds

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

The above action does the following:

  • If necessary it will bootstrap the Ant code. Bootstrapping involves the manual compilation of enough Ant code to be able to run Ant. The bootstrapped Ant is used for the remainder of the build steps.
  • Invokes the bootstrapped Ant with the parameters passed to the build script. In this case, these parameters define an Ant property value and specify the “dist” target in Ant’s own build.xml file.
  • Create the ant.jar and ant-launcher.jar JAR files
  • Create optional JARs for which the build had the relevant libraries. If a particular library is missing from ANT_HOME/lib/optional, then the matching ant- JAR file will not be created. For example, ant-junit.jar is only built if there is a junit.jar in the optional directory.

Other ways to build and install

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)
sh build.sh install (Unix)

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

  build install-lite        (Windows)
sh 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.

Checking the Installation

Now we have built and installed Ant, and we can check if everything works properly, as shown below.

[root@nimal ~]# which ant
/usr/local/ant/bin/ant
[root@nimal ~]# ant -version
Apache Ant version 1.7.0 compiled on November 13 2007

This is just a brief document related to Ant installation which I did on a RHEL4 server. I think this should work on other environments as well, but I’m not sure about that. If someone of you try this using my doc and if you are successful just let me know via a comment. Also if you have any doubts you can ask me, but I can assure answers, if-and-only-if its under my intellectual capacity :).

Reference: http://ant.apache.org/manual/install.html

3 thoughts on “Ant: Installation”

  1. Hi Nimal, The steps you have mentioned for the installation is really helpful. But I want a help from your end for the following:

    Can you please help me out by providing the steps to install and configure ant in an Unix system.

    Regards
    Mahesh

  2. Am I missing something here?

    Mahesh, Nimal,

    This blog appears to talk about the installation procedures for Unix/Linux.

    So, I could not understand what more you need.

Leave a Reply