Saturday, November 14, 2009

Notes Ant


Introduction
Install
Running Ant
Structure
Example
Using Ant with Eclipse


Introduction
============
- Ant is like a Makefile. The configuration is called by default as
"build.xml"
- Ant is a Java program.
- Requires xml parsers and Java installed


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



Install
==========
1. Unpack ANT into a directory eg. c:\ant.
2. Set Env variables:

Windows and OS/2
Assume Ant is installed in c:\ant\. The following sets up the environment:

set ANT_HOME=c:\ant
set JAVA_HOME=c:\jdk1.2.2
set PATH=%PATH%;%ANT_HOME%\bin

(Start - > Control Panal -> System -> Advanced ->Env Variables)

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/local/jdk-1.2.2
export PATH=${PATH}:${ANT_HOME}/bin

(/etc/profile.d/*.sh)


Running Ant
============
To run:
ant -buildfile

ant -buildfile test.xml -Dbuild=build/classes dist
runs Ant using the test.xml file in the current directory,
on the target called dist, setting the build property to
the value build/classes.


Structure
==========
Structure of build.xml:
attribs: name, default (target), basedir
Children: , ,

attribs: name, depends, if, unless, description
Children: various tasks

Tasks
attribs: id

attribs: name, value, file, location, url, refid, resource,
environment, classpath, classpathref, prefix
Example
========
simple example build file



The following allows ant to make use of local environment variables







Using Ant with Eclipse
=======================
1. Create a new xml in Eclipse, to be the ant build file, eg. build.xml
2. Open the build.xml file with Eclipse editor
3. Edit the xml file, note there is context sensitive help in Eclipse.
4. To run the build.xml: Run As -> Ant Build, then select targets
to be build.

No comments: