This document describes how I installed Ant 1.5.2 and various tasks on my
iMac running Mac OS X 10.1.5 (Puma).
The instructions also work with 10.2 (Jaguar) and 10.3 (Panther).
This is one way to do so; others are possible.
Everyone has his
'One True Way' to organize software.
Improvements are welcome!
Some program capable of downloading from the internet. These instructions will reference wget but almost anything will do, including your web browser. You will also need to use sudo, an application which gives a user the ability to run commands as root while logging all commands and arguments.
Apache Ant is a Java-based build tool. It processes configuration files, named build.xml by convention, written in XML.
If you're planning to write your own build files, I highly recommend the purchase of Java Development with Ant, written by and . Ant comes with documentation, but it'll make much more sense after reading this book.
Start Terminal.app which can be found in /Applications/Utilities and get ready to type...
Download the compressed binary distribution and save it to /usr/local, where it would usually be installed by default. Most Un*x install scripts use either /usr/local or /opt as their default installation path. Don't swim upstream if you don't have to.
The /usr/local directory is owned by root; administrator authorization will be required in order to affect changes. Having it owned by another account protects against accidental changes.
Unpack the compressed binary distribution. The resulting folder will be /usr/local/apache-ant-1.5.2
Delete the binary distribution file as it is no longer needed.
Create symbolic link from /usr/local/apache-ant-1.5.2 to /usr/local/ant. This will map the physical directory to a logical directory. We do this so settings do not have to be changed with each upgrade.
Make sure symbolic link exists from /usr/local/bin/ant to /usr/local/ant/bin/ant.
If the output looks like this, a link already exists and nothing further need be done.
If the output looks like this instead, create the symbolic link.
It can be handy to integrate the Un*x installation with the Mac OS X style file hierarchy. The layout looks like this:
$HOME ..../Developer ......../Documentation ............/Tools ................/Ant@-> ../../Tools/Ant/Home/docs ......../Tools ............/Ant ................/Home@-> Versions/Current ................/Extensions@-> Home/lib ................/Versions ..................../Current@-> 1.5.2 ..................../1.5.2@-> /usr/local/apache-ant-1.5.2
Here are the commands to create the integration hierarchy.
Whew! You're finished. Wanna see what you made?
Fortunately, configuration of Ant is fairly trivial. Two environment variables, ANT_HOME and JAVA_HOME, must be set to properly use Ant. While they can be set manually when needed, that's a pain. Normal setup will place them into one of the various shell startup files.
Using a text editor (like pico or vi), append these lines accordingly. Edit the two files below as shown to automatically have these environment variables set (upon login) for either csh-based or sh-based shell. Note that the different shells use similar but not identical syntax.
| UW PICO(tm) 2.3 | File: /Users/johndoe/.login |
| UW PICO(tm) 2.3 | File: /Users/johndoe/.profile |
Check that this worked with the following commands. If not, make the appropriate corrections before proceeding.
The last thing to check is your PATH environment variable. Apple changed the default paths after Puma, which dropped /usr/local/bin from certain setups. If the output doesn't include it, make appropriate changes to your setup.
Let's do a basic checkout to make sure everything is installed correctly.
Create a simple project named GettingStarted.
Download the source code and build file. Put the source code in the src directory. Arrange them as such.
$HOME ..../Projects ......../GettingStarted ............/src ................/Main.java ............/build.xml
Now invoke Ant to build this simple project.
Buildfile: build.xml
init:
[mkdir] Created dir: /Users/johndoe/Projects/GettingStarted/build/classes
[mkdir] Created dir: /Users/johndoe/Projects/GettingStarted/dist
compile:
[javac] Compiling 1 source file to /Users/johndoe/Projects/GettingStarted/build/classes
execute:
[java] a
[java] b
[java] /Users/johndoe/Projects/GettingStarted
default:
BUILD SUCCESSFUL
Total time: 13 seconds
Anyone wondering how much effort will be required to upgrade when the next version comes out? Here are the instructions required to update to Ant 1.5.4.
Nothing new here as compared with the installation instructions except the version change.
Unpack the compressed binary distribution. The resulting folder will be /usr/local/apache-ant-1.5.4
Delete the binary distribution file as it is no longer needed.
Create symbolic link from /usr/local/apache-ant-1.5.4 to /usr/local/ant. This will remap the logical directory to use the new version.
This will be much simpler than creating the Mac OS X layout was originally. To upgrade, create a new directory under 'Versions' and change the 'Current' symbolic link to point to the new release.
Since Ant build files are extensible, many third party tools are also available as Ant tasks. This allows invoking them as though they were an integral part of Ant. There are several methods to allow this but the simplest is to make use of Ant's library directory. This usage corresponds to how $JAVA_HOME/lib/ext (or /Library/Java/Extensions on Mac OS X) works to extend Java. Essentially, JAR files copied to this directory are automatically in the classpath of Ant's JVM.
I recommend appending the tool's version number to the basename of each JAR file copied to this location. It makes it a quick and easy task to determine what version is being used.