This is part of Getting Started

Ant

Ant is a tool for running scripts that automate the process of building and deploying large Java projects. You'll use Ant from the Command Line to Build LimeWire, run a Test, and Make the JARs.

Ant is also built into Eclipse. To use it there, give Eclipse access to Java Source Code.

Get Ant

Get Ant from the Apache Software Foundation's Web site for the project:

http://ant.apache.org/

On the left, under Download, click Binary Distributions. On that page, under Current Release of Ant, choose the .zip archive to download a file with a name like apache-ant-1.7.0-bin.zip.

Unzip the file, and you'll have a folder with a name like apache-ant-1.7.0 and files like fetch.xml and get-m2.xml inside. Change this folder's name to just ant and move it to your hard drive. For example, on Windows, make the paths to files like this:

C:\ant\fetch.xml
C:\ant\get-m2.xml
C:\ant\bin\antRun.bat

That's all you have to do to get the Ant software onto your computer. There is no setup program.

Set the Paths

Before you can use Ant, you have to tell the Command Line the paths where Ant program files are located on your computer. You also have to show it where the Java Development Kit is. On Windows, open Cygwin and type four commands like these:

export PATH=$PATH:/cygdrive/c/ant/bin
export PATH=$PATH:/cygdrive/c/program\ files/java/jdk1.6.0_03/bin
export JAVA_HOME=/cygdrive/c/program\ files/java/jdk1.6.0_03
export ANT_HOME=/cygdrive/c/ant

In Cygwin, the Windows C:\ drive has the Unix path /cygdrive/c. The first two commands add the Ant and Java bin folders to the PATH environment variable. The third and fourth commands set the environment variables JAVA_HOME and ANT_HOME. This example shows the folder name jdk1.6.0_03, but on your computer, the version number may be different. Find the folder where the Java Development Kit is installed, and type its name instead.

To make sure you've set the paths correctly, type ant -version:

Kevin@limewire ~
$ ant -version
Apache Ant version 1.7.0 compiled on December 13 2006

Edit .bashrc

It's somewhat cumbersome to type these four lines each time you open Cygwin and want to use Ant. To have them run automatically, add them to your .bashrc file. For our example on Windows, the .bashrc file has the path:

C:\cygwin\home\Kevin\.bashrc

The commands in this file run each time you open a new Cygwin window to get to the command line.

If you switch to a new version of the Java Development Kit, remember to go back and edit the commands you added to your .bashrc file. If editing the file doesn't work or causes and error, make sure you used a text editor that can save the file with Unix line endings instead of Windows line endings.

Learning Ant

When you type ant in a directory, Ant runs. By default, it looks for a file named build.xml. This script, written in XML, tells Ant what to do. LimeWire's Source Code comes with about 20 build.xml files, in directories like core, gui, and tests. Tasks within them turn .java files into .class files, run test code, and package files into .jar files.

To figure out how an Ant script works, refer to the Apache Ant User Manual. For an introduction to using Ant and writing Ant scripts, check out Ant: The Definitive Guide by Steven Holzner. The Cheat Sheet also has some examples of using Ant.