Home > Apache Ant, General, Technology > Basics of ANT

Basics of ANT

Here are some basics of Apache ANT

Why ANT?

Ant is used for building projects, they are very small and capable of building complex projects. Initially, Ant was part of the Tomcat code base, when it was donated to the Apache Software Foundation. It was created by James Duncan Davidson, who is also the original author of Tomcat. Ant was there to build Tomcat, nothing else.

Soon thereafter, several open source Java projects realized that Ant could solve the problems they had with Makefiles. Starting with the projects hosted at Jakarta and the old Java Apache project, Ant spread like a virus and is now the build tool of choice for a lot of projects.

In January 2000, Ant was moved to a separate CVS module and was promoted to a project of its own, independent of Tomcat, and became Apache Ant.

The first version of Ant that was exposed to a larger audience was the one that shipped with Tomcat’s 3.1 release on 19 April 2000. This version has later been referred to as Ant 0.3.1.

The first official release of Ant as a stand-alone product was Ant 1.1, released on 19 July 2000. Refer the Link for more information.

Now let’s get into some basics.


  • Download apache ANT zip file from http://ant.apache.org/bindownload.cgi
  • Unzip in to the file system
  • Set the environment variable ANT_HOME to bin directory of ANT folder you just unzipped in step above
  • Now open a command prompt and type in ‘ant’ as command
  • You should see the following comment, this ensures that you are now ready to take off…


The Ant-Contrib project is a collection of tasks (and at one point maybe types and other tools) for Apache Ant. This Software is distributed under the Apache Software License.

We’ll use Ant-Contrib for using if-else condition, for-each iterator

Note: ant-contrib jar file should be copied into <Apache_home>/lib directory . ANT script should be stored as build.xml file. Ant command should be executed from the directory that contains build.xml

A simple build.xml file looks like this:

<project name="Basic" default="build" basedir="."> <!-- there should be a target by name 'build', other wise error would be thrown-->

<target name="build"  depends="compile" description="compile source code"/> <!--this target calls 'compile'-->

<target name="compile"> <mkdir dir="${build.classes.dir}"/> <!-- create directory for storing compiled java code as .class-->

<javac destdir="${src.dir}" debug="true"> <!-- source directory, where you've java code-->

<src path="${src.audit.dir}"/>






Here is a sample example for including ant-contrib jar file.
 <project name="DefaultTAPITemplate" default="build" basedir="."
 <taskdef uri="antlib:net.sf.antcontrib"


Let's discuss on how to use for-each and if-else in next post...

  1. January 18, 2011 at 12:13 AM

    Sending someone a message…they don’t reply…they must be out…then they post a Facebook status. Great, they’re ignoring me.


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: