Contents [0/8] |
Ant: What is it? [1/8] |
Ant: Download [2/8] |
Ant: Setup [3/8] |
Ant: Environment Settings [4/8] |
Ant: Running Ant [5/8] |
Ant: The development directory [6/8] |
Ant: The build file - intro to XML [7/8] |
Ant: A concrete example [8/8] |
Ant: What is it? [1/8] |
Ant
Ant stands for Another Neat Tool
Basically, Ant is a Java based build tool. It uses Java to build Java code for you. It also happens to have a number of interesting features that make life for the Java developer a lot easier.
Ant has been described as make without make's wrinkles.
Ant was written originally to build Tomcat, and the code was quickly re-used by other projects, and Ant was turned into its own project. Ant is now a top level apache project, it is not under the jakarta group of projects.
Ant: Download [2/8] |
Download it from here. You should get the .zip version if you are on Windows, get the tar.gz if you are on Unix. For now, just get apache-ant-1.5.4-bin[.zip or .tar.gz].
On Windows, unzip it to a directory using your favorite zip tool. With
WinZip, you just double click on the file, click the extract
button, and choose a good directory to unzip it to. I
recommend something close to the root of your drive, like
D:\
or C:\
or C:\se452
. Once
extracted, it will be in a directory called
apache-ant-1.5.4
. We will call this directory
ANT_HOME
On Unix, extract the ant tarball to a directory where you
have permissions to keep applications. On linux, this might
be /usr/local
, on HP it might be
/apps
or /opt
. If you don't have
root access, you can install Ant anywhere.
With Gnu tar, you can use the command tar -xvzf
apache-ant-1.5.4-bin.tar.gz
. With the standard tar,
use something like gzip -c
apache-ant-1.5.4-bin.tar.gz | tar xf -
from the
directory where you want the ANT_HOME
to
be.
With either download, you can check the PGP signature of the file using pgp or gpg.
Ant: Setup [3/8] |
Ant is a command line tool, although it has been integrated with numerous IDEs. Since we are using the command line, it will fit in well with our development environment.
Once Ant has been extracted, you will need to setup your
environment to run from the command line properly. This
will involve setting the PATH
and
ANT_HOME
environment variables.
From the command line:
On Windows:
set ANT_HOME=C:\apache-ant-1.5.4 set PATH=%PATH%;%ANT_HOME%\binOn Unix (bash):
export ANT_HOME=/usr/local/apache-ant-1.5.4 export PATH=$PATH:$ANT_HOME/bin
Ant: Environment Settings [4/8] |
To make this the default on your machine:
On Windows (NT-ish systems):
->
Settings->
Control
Panel->
System
ANT_HOME
On Windows (2000/NT/XP-ish systems)
->
Settings->
Control
Panel->
System
->
Environment Variables
ANT_HOME
in the Variable Name box.
On Windows 9x:
Add an entry in your autoexec.bat for ANT_HOME and PATH that is identical to the settings above from the command line.
On Unix:Add an entry in your .profile for ANT_HOME and PATH that is identical to the settings above from the command line.
Ant: Running Ant [5/8] |
OK, enough setup. Now to run Ant. You should be able to go to a random directory in a command window and type ant and see something like the following on your screen:
Buildfile: build.xml does not exist! Build failed
This is a good thing. This means ant is now working. Now we will look at the setup of your development directory and the build file to compile your code.
Ant: The development directory [6/8] |
So far, you have been developing code in a directory, running java and javac by hand. Perhaps you have written .bat or .sh scripts to run these commands repetitively. You also have probably set your system classpath at the global level for this class.
By setting up Ant properly, we'll eliminate the need for this.
Create the following directory structure on your computer where you will work on your homework assignments
base directory (like c:/se452 or /home/username/se452 | +------>build.xml /src +-------->/html /java /sql /etc., etc. /lib
The /src directory will contain all of your source files in their full package directories
The /lib directory will contain any third party .jar files that are supplied by me or others
Other directories will be created as we go through the quarter and by the build process itself.
Ant: The build file - intro to XML [7/8] |
The build file is written in XML. This means that it has to conform to XML rules, as well as be properly configured for what Ant expects.
Some XML basics.
The Ant build file structure.
project property property target task task target task task
Properties are settings that you use throughout your build
file. They are set, and then dereferenced in the build file
by using the following syntax: ${property}
A build file consists of multiple targets. Targets can be dependent on one another so they are always run in the correct order. For example, you would always need to run an init target that makes directories where your javadoc will go.
A target consists of multiple tasks. Ant contains built-in tasks for some of the following:
It also has optional tasks for things such as:
Ant: A concrete example [8/8] |
An example build file
Revised: 2003/09/28