Ant – To write a simple build file

Ant Definition

Ant is actually a tool which is used to write build file for web applications.

By writing the build file our primary aim is to transfer the files to certain folders after the build process.

Ant is a tool which helps a developer to customize a build process.

Contents of build file

Mainly there are four elements or tags  are present in the build file, they are project, targets, tasks and properties. A simple build file must contain project tag and a default target.

1) project tag

The project tag has got three attributes namely name, default and basedir.

name:     Name of our project.

default:  This is the default “target” used when no target is supplied during build process.

basedir: This is the root directory to all other directories.

2) target tag

A target is also a tag which is present in the build file. A target contains one or more jobs or tasks defined in it. We can use a target during our build process while specifying the build file.

For example, the build file for our project is “project_build.xml”. One target named “installdb” is specified in that target. This target may contain task(s) to install anew database for the application. So when ever our project needs a new database then just give this “installdb” target during build process.

example:- Linux (command prompt)

ant -f /home/username/project/project_build.xml installdb

Note:- the user have to give option f during the build process.

3)task tag

A task specifies a single task. for example to delete a certain directory(build out-put).

Example:- <delete dir=/home/username/project/build-output />.

Some of the commonly used tasks are javac,copy, mkdir, echo, tar, gzip, include etc

4)property tag

These are actually general names given that are repeatedly used in our project. These are used as a name and value pair.

example:- Project home path will be “/home/username/project”. Here we can create a property named “Home” as “/home/username/project”

<property name=”Home” value=”/home/username/” />

So by just specifying “${Home}” interpretation by the build process will be “/home/username/”

This “Home” property can be reused in other places of the build file.

example:-  <property name=”JAVA_HOME” value=”${Home}/jdk1.6″/>


2 Responses to “Ant – To write a simple build file”

  1. rag Says:

    wat r u? i mean wat u do?
    r u a build engineer

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s