Monday, 11 February 2013

How to configure Apache Ant on Mac OS X?

Installing Apache Ant on MAC is quite different from Windows.
We use Terminal instead of cmd prompt in MAC.

Steps to Install Apache Ant on MAC OS X:

1. Down­load the lat­est ver­sion of Apache Ant.

2. Open the Ter­mi­nal application.

3. Now you’ll need to manip­u­late files in the /usr/local/ which means you’ll need root priv­i­leges. To get them use “sudo” com­mand (lucky you are, Mac OS X already has sudo as well) and enter your root pass­word.
sudo sh

System_name:~ Username$ sudo sh

4. Move/Copy the archive into /usr/local/:
mv apache-ant-1.8.4-bin.tar.gz /usr/local/

5. Go to /usr/local/:
cd /usr/local/

sh-3.2$ cd /usr/local/

6. Unar­chive the sources:
tar xvzf apache-ant-1.8.4-bin.tar.gz

sh-3.2$ tar xvzf apache-ant-1.8.4-bin.tar.gz

7. Change the apache-ant-1.8.4 direc­tory owner to your nor­mal user:
chown YourUsername:YourGroup apache-ant-1.8.4

If you’re not sure about the user­name and the group sim­ply type “ls –la”. This com­mand will print out all files and direc­to­ries in the cur­rent direc­tory (/usr/local/). The Ant sources you just copied will have your user­name and your group:
-rw-r--r--@  1 Sams staff  5425171 12 Feb 15:24 apache-ant-1.8.4-bin.tar.gz

sh-3.2# ls -la
total 10600
drwxr-xr-x   5 root          wheel      170 Feb 12 16:05 .
drwxr-xr-x@ 11 root          wheel      374 Dec 29 19:47 ..
drwxr-xr-x@ 14 root          wheel      476 Feb 12 16:05 apache-ant-1.8.4
-rw-r--r--@  1 user_name  staff  5425171 Feb 12 15:24 apache-ant-1.8.4-bin.tar.gz
drwxr-xr-x   4 root          wheel      136 Dec 29 19:47 bin

8. Now you can run Ant by typ­ing /usr/local/apache-ant-1.8.4. Not very con­ve­nient, huh?

9. Let’s make it work more friendly:
First, cre­ate a sym­bolic link to refer the appli­ca­tion as ant instead of apache-ant-1.8.:
ln -s apache-ant-1.8.4 ant

sh-3.2# ln -s apache-ant-1.8.4 ant

Sec­ond, add the fol­low­ing lines into your shell con­fig:
export ANT_HOME_DIR=/usr/local/ant
export PATH=${PATH}:${ANT_HOME_DIR}/bin

sh-3.2# export ANT_HOME_DIR=/usr/local/ant
sh-3.2# export PATH=${PATH}:${ANT_HOME_DIR}/bin

10. Restart your Ter­mi­nal and type “ant”. If it says “Build­file: build.xml does not exist! Build failed” which means that Apache Ant works correctly.

Else open terminal and type,
ant -version

1 comment: