How to build your applications using ANT

Posted by kumarjit in Software, Web Design Tutorials, Web Hosting, Web Hosting Tips

1 Star2 Stars (1 votes, average: 0.00 out of 5)

How to build your applications using ANT

ANT stands for Another Neat Tool. It was built by Apache thus also known as Apache ANT.  It is open Source and works across different platforms. Basically it is a tool to which helps in automating different tasks/processes that program developers have to do on a daily basis.

 How to build your applications using ANT

Why ANT and not others?

The main difficulty faced by programmers while using other build tools like Gnumake, Nmake, JAM, etc. was while working in different platforms. All of these are shell based and limit your operations to only the OS type you are working on. ANT on the other hand is NOT shell-based rather it is extended using JAVA classes. Config files are XML-based and by just calling a target tree your tasks are executed, thus the term “Neat”.

How to install ANT and start building?

Installing Apache ANT is quite simple and works with any JAVA environment (JRE or JDK). The current new version of ANT is Apache ANT 1.8.1. One has to first download the binary files (available on the official ANT website) and then just add the location of the binary folder to the location of the environment variable. Then set ANT_HOME variable to where ant is installed.

How to build your applications using ANT

Ant is build into many IDEs too (WSAD/RAD/Eclipse). All have a specialized “Ant View”. You can use it automate not only JAVA projects but any complex repetitive task.

Getting started with ANT

Since most of the time ANT is used to compile and build in JAVA, it would be more appropriate to discuss this first. Compiling and building in JAVA is basically generating, compiling and building JAR files.

Working with ANT can broken down to three key aspects; Target, Tasks and Properties.

Target is a set of tasks to be executed.

Task is a piece of code to be executed (Can have multiple attributes).

Properties are set are not a variables.

You can start off by first creating a build.xml file in the same path as of the sources (sources are generally put in the sub-directory SRC).

For compiling we need a jar file in the classpath. To define the location of this file you need to create a property file.


#             File Name:



The tasks e following operations
Clean the build directory if exists.
Create the build directory where the new classes will be built.
Compile the java classes.
Build a jar file from the java classes

The build.xml file

<project basedir=”.” default=”hello-world”>
<property value=”build”/>
<property file=””/>
<delete dir=”${build}”/>
<target depends=”clean”>
<mkdir dir=”${build}”/>
<target depends=”init”>
<!– Compile the java code –>
<javac srcdir=”src” destdir=”${build}”>
<pathelement location=”${env.LIB}/required-jar1.jar”/>
<pathelement location=”${env.LIB}/required-jar2.jar”/>
<target depends=”compile”>
<!– Build the jar file –>
<jar basedir=”${build}” destfile=”${build}/new-jar.jar”/>

Here we have simple created a jar file using ANT build file. This could also have been done by few batch commands in command prompt but the advantages using ANT are that the files can easily reused and parameterized, also sub projects can be created and other operations too can be implemented. Few operations which come with ANT are zip file task, editing text/xml files, sql operations, etc.

Create and build exciting applications with Bounceweb hosting!

Be Sociable, Share!

Leave a Reply

You must be logged in to post a comment.