Getting started with Ant.
Do you know what Ant is?
========================
If you don't know what ant is,
read "backgroundAboutAnt.txt" first.
Acknowledgements
================
Much of the material here is adapted from:
http://blog.ideoplex.com/software/java/antTutorial2.html
Getting ready to use Ant on strauss
===================================
Before we can start using Ant, we have to make sure
we can find the "ant" command.
I've installed Ant in the following directory on strauss:
/www/htdocs/CIS/software/dist/apache-ant-1.6.5/
So on strauss, you'd need to add the following to your .localenv
file to make Ant work for you:
if -d /www/htdocs/CIS/software/dist/apache-ant-1.6.5 then
setenv ANT_HOME /www/htdocs/CIS/software/dist/apache-ant-1.6.5
setenv NEWPATH $ANT_HOME/bin:$NEWPATH
endif
See my notes in the file topics/java/compilingOnStrauss for
hints about making the .localenv file work on strauss.
For bash, use (according to http://ant.apache.org/manual/index.html)
something like the following.
export ANT_HOME=/www/htdocs/CIS/software/dist/apache-ant-1.6.5
export JAVA_HOME=/usr/jdk1.5
export PATH=${PATH}:${ANT_HOME}/bin
Creating your first ant build file
==================================
We'll work with the file HelloWorld.java.
We'll set up a file called "build.xml", which is the
default name for an ant "build file".
Note that we have no class file in our directory before
we type "ant". Afterwards, we do!
> ls
HelloWorld.java backgroundAboutAnt.txt build.xml gettingStartedWithAnt.txt
> ant
Buildfile: build.xml
compile:
[javac] Compiling 1 source file
BUILD SUCCESSFUL
Total time: 4 seconds
> ls
HelloWorld.class backgroundAboutAnt.txt gettingStartedWithAnt.txt
HelloWorld.java build.xml
Then, if we type ant again, note that magically, "nothing happens".
Ant is smart enough to realize that we don't need to recompile,
because we haven't changed anything.
> ant
Buildfile: build.xml
compile:
BUILD SUCCESSFUL
Total time: 2 seconds
>
Then, we make a change to HelloWorld.java, and re do the ant command:
> emacs HelloWorld.java
> ant
Buildfile: build.xml
compile:
[javac] Compiling 1 source file
BUILD SUCCESSFUL
Total time: 5 seconds
>
And, we magically recompile.
Now, let's make it more interesting by creating a jar file too.
(Read up on jar files in topics/java/deployment/jarFiles if you
don't know about jar files yet!)
New contents of build.xml:
References and further reading
==============================
References:
http://blog.ideoplex.com/software/java/antTutorial2.html
For more Ant tutorials from the same source:
http://blog.ideoplex.com/software/java/
A good overview of how to use Ant in practice:
http://ant.apache.org/ant_in_anger.html