How to install Apache Ant

### Overview ###

# Apache Ant is a “pure Java build tool”, and is used a lot in the Java world as a replacement for OS-specific build tools like “make”, “build”, “jam”, etc.

# Because Ant is pure-Java, it makes it easier to install/build Java applications due to its Java-by-nature code portability. The Catch: as long as the Java applications you want to build use Apache Ant as the build mechanism.  If they don’t, Ant is not gonna help you.  But most major Java apps now use Ant as the build mechanism, so better to have Ant installed than to not have Ant installed.

# Apache Ant is OS-independent, so it doesn’t matter what operating system you’re using to build your applications from source, but Apache Ant is Java-dependent, so it does require Java be installed (like Sun’s JRE, JDK, OpenJDK, IcedTea, etc.) and does require that you have a user/system environment set called $JAVA_HOME and pointed to the location that you have your Java package installed.  

# Side note: This can be confusing to some Mac users (me) because they know (or believe) Java is already installed with Mac OS X Leopard, but they (I) don’t know the longass directory it’s installed to (see http://developer.apple.com/java/javaleopard.html). So I choose to install a fresh version of Java SDK onto my Mac while I already believe to have Java installed, but I’m not 100% sure where, how, why,…okay, so I install it so I know where the heck it is on my computer and, most importantly, how to delete it and start over if tides get rough… please read on…

# Why bother with Apache Ant as a Flex on Ruby on Rails developer?  Most importantly, you’ll need it to install JRuby!!! JRuby allows Ruby programmers (me) to connect to the vast libraries and applications and technologies and money-paying gigs (not me) that exist in the Java world.  Hopefully more answers to come…

# Bottom Line: Apache Ant is pretty freakin cool for what it does. Think of Apache Ant doing the same for Java that the brilliant Rake does for Ruby.  Ant greatly simplifies the installation process of most major Java applications from source code. While you could theoretically install a pure-Ruby application using Apache Ant, and at the same time, you could theoretically install a pure-Java application using Rake, this is not common practice.  So for now just think of it as, for lack of a better brain-reminder, Ant installs Java stuff and Rake installs Ruby stuff.

# Why not build Ant from source code?  Well, because it’s not necessary.  It’s just one extra step to build.sh before installing…

### INSTALL APACHE ANT ###

1. DOWNLOAD and UNARCHIVE the latest stable version (”binary distribution”) to wherever the heck you desire on your computer.  I use “wget” as my file downloader, but you may prefer something else, like “curl”.  You also may have a preference of archive file type - here are the offered tar.gz, tar.bz2, and .zip options for Ant:

wget http://www.mirrorgeek.com/apache.org/ant/binaries/apache-ant-1.7.1-bin.tar.gz
tar xzvf  apache-ant-1.7.1-bin.tar.gz

# OR

wget http://www.mirrorgeek.com/apache.org/ant/binaries/apache-ant-1.7.1-bin.zip
unzip  apache-ant-1.7.1-bin.zip

# OR

wget http://www.mirrorgeek.com/apache.org/ant/binaries/apache-ant-1.7.1-bin.tar.bz2
tar -xvf  apache-ant-1.7.1-bin.tar.bz2

2. Because we downloaded the binary distribution of Apache Ant, and due to the portability of binary distros as well as Java projects like Ant, all we need to do is create an Ant environment variable called $ANT_HOME pointing to this (un)tarred location.

YOU CAN PUT THIS DIRECTORY ANYWHERE YOU WANT. I’ve chosen to leave it in my default ~/Downloads folder.

# open my Mac bashrc environment profile in the “nano” text editor
sudo nano /etc/bashrc
# or wherever you set env variables, perhaps ~/.bash_profile

# make sure you have Java installed and JAVA_HOME set
export JAVA_HOME=/usr  # leads to… /bin/java

# or, if you followed my other post and installed SoyLatte Java 6 JDK for Mac
export JAVA_HOME=/Users/me/Downloads/soylatte16-i386-1.0.3

# add java runtime to environment path
export PATH=$JAVA_HOME/bin:$PATH

# point to your Ant binary distribution folder
export ANT_HOME=/Users/me/Downloads/apache-ant-1.7.1

# add the Ant “bin” directory to your $PATH environment variable
export PATH=${ANT_HOME}/bin:${PATH}

# Cool, now we have Ant installed.

# First, save my profile.
# Then refresh it with “source”
source /etc/bashrc  
# or something like source ~/.bash_profile 

4. Now we can use Ant.  hmmm… Enjoy ?  Okay, let’s make sure it installed correctly, then enjoy Apache Ant.

ant -version
Apache Ant version 1.7.1 compiled on June 27 2008

 

DONE!

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Comment: