jeffheaton's picture
in

    Apache Ant is a software application used to build Java projects. This book’s examples include an ant build script (build.xml). To compile the examples in this book using this build script, you will need to install Apache Ant. The latest version of Apache Ant can always be found at the following URL:

http://ant.apache.org/

    When you download Apache Ant, you will obtain a tar.gz file. Using the finder, copy this file to your user directory. The rest of the install will be done from a terminal window. Open a terminal window and enter the following command:

su

    This will transform you into the super user. To install ant, you must be the super user. If this is the first time that you have logged in as the super user you will be given a brief warning.

    Next, we will need to create a directory to store ant in. Do this with the following command:

mkdir /usr/local

    You may get an error telling you that this directory already exists. If you do get this error, simply ignore it. Now you need to move to this directory with the following command:

cd /usr/local

    You are now ready to unpack the ant archive that you downloaded earlier. This is done with the following command:

tar zxvf /home/jeff/apache-ant-1.6.5-bin.tar.gz

    Of course, if you downloaded a different version, make sure to change the filename appropriately. Also make sure you use your home directory. In the command above, the home directory is set for a user named “jeff”. If the unpack is successful, you will see dozens of files stream by on the terminal. When it is all done, your terminal will look similar to Figure D.2.

Figure D.2: A Successful Ant Unpack

A Successful Ant Unpack

    You no longer need to be the super user for the rest of this install. Enter the following to exit super user status:

exit

    You should also move back to your user directory, with the following command:

cd

    Now you need to edit your profile using the vi editor. This will allow you to easily start the ant application. Use the following command:

vi .bash_profile

    Once inside of vi, move to the bottom of the file and press “i”. This will put you into insert mode. Enter the following three lines at the bottom of your file. Enter them exactly as you see here. Adjust for version differences if necessary.

export JAVA_HOME=/Library/java/Home
export ANT_HOME=/usr/local/apache-ant-1.6.5
export PATH=${PATH}:${ANT_HOME}/bin

    Make sure you do not erase data already in the file! This is very important! Once you enter these lines, your screen should look something like Figure D.3.

Figure D.3: A Simple Profile

A Simple Profile

    Once you have entered these lines, press the colon(:), type “wq!” and press enter. This should get you back to the command prompt. Close this terminal window and open a new one so that the changes take effect.

    You can now test Apache Ant. Open a new terminal window and enter the command “ant”. You should see ant display an error message, as seen in Figure D.4.

Figure D.4: Testing Ant

Testing Ant

    Ant could not find any files to build. That problem will be corrected as we prepare to compile the book’s examples.


Copyright 2005 - 2012 by Heaton Research, Inc.. Heaton Research™ and Encog™ are trademarks of Heaton Research. Click here for copyright, license and trademark information.