This is the first in a multi-part series on setting up ANT to manage a development environment, run tests, and do some other cool stuff.
Downloading ANT
Head over here: http://ant.apache.org/bindownload.cgi and download the latest binary distribution. It comes in a zip or a tarball, whatever you prefer. You can extract it wherever you want. (I put mine in C:\ant for simplicity)
Trying it out
So ANT, like many other Apache tools, is command line only, which is cool because the command line really separates the men/women from the boys/girls. If you’re not familiar with the command line, you should pause for a minute, head over to this site and play around a bit.
Take a look in the ant directory. You’ll notice some folders:
- bin - Holds all of the ant binaries. This is what you’ll actually be executing when you run an ant script.
- docs - Documentation for ant. You can read through this for details on writing ANT scripts. If you’re seriously considering using ANT, I would check out the book ANT In Action by Steve Loughran and Erik Hatcher
- etc - Configuration files for ant. You probably won’t need to touch these at all.
- lib - JAR Libraries that ant uses during execution.
Start by just simply, running the program.
Oops… although we dropped ant on our hard disk, Windows doesn’t know where to find the executable yet. We have to add the ant binary directory to our Windows PATH environment variable. Let’s go ahead and do that. Right click “My Computer” in the start menu and click Properties.
Click on “Advanced System Settings”
Click on “Environment Variables”. Under the System Variables, scroll down to Path and click on the Edit button.
Notice how the value has a bunch of directory locations in it. This “path” variable represents where windows searches for executables when you type a command in the command prompt, that isn’t in your current directory or isn’t a complete path to the executable.
The paths are separated by semicolons, so let’s add a semicolon to the end of it, and add on the path C:\ant\bin, Click OK, and we should be good. Now, let’s open up a new command prompt and try again.
Well… almost… If you’re getting the above message like I did, then you’ve got a small problem. It looks like ANT is looking for a java library that isn’t in whatever java version I have installed. The best way to make things work nicely with ANT is to download the latest JDK (not the JRE… the JDK contains development tools which don’t normally come with just the standalone JRE). If you already have it in your system, then all you have to do is set the JAVA_HOME path to point to your JDK rather than your JRE.
Go back to the Environment Variables window and add the JAVA_HOME system variable, with its value being the location to the JDK Root (in my case, it was C:\Program Files\Java\jdk1.6.0_04)
Once you’ve got that setup, let’s give this one more shot. Open a new command prompt, and try again.
Success! Kinda… Right now there’s no build file (defines what ant should to do build the project) in my default home directory. Besides, running an ant build on my home directory doesn’t make sense, since my home directory isn’t even a bulidable project. Next time, we’ll setup a sample project and build it… oh yes, we will build it.









