I just spent a good deal of time trying to get the optional FTP task working with the default ant install on OS X 6.4. The most useful information on this topic that I found online was right here: http://mactip.blogspot.com/2009/02/ant-ftp-task-libraries-jakarta-oro.html. If you scroll down to the comments section:
"Whoever built the Ant distro from Apple didn’t have all the optional JAR files to hand, so things like the ssh task wont work even if you add jsch.jar to ~/.ant/lib"
— SteveL (on the Ant dev team)
So that pretty much nailed it. Time to upgrade. For this you’re going to need:
- The latest version of ant. (1.8.2 as of this post)
- The Apache Commons Net jarfile. (2.2 as of this post)
First, make sure you even have Ant installed. The easiest way to do this is just to check the version:
$ ant -version $ Apache Ant(TM) version 1.7.1 compiled on February 10 2010
Great! Keep track of which version you’re using now; we’ll compare version strings to verify our install once we’re done.
Now Ant is kind of buried in OS X; the $PATH variable points to a symlink which points to another symlink. To find out where ant really is, just follow the chain:
$ which ant /usr/bin/ant $ ls -la /usr/bin/ant lrwxr-xr-x 1 root wheel 22 Nov 11 18:04 /usr/bin/ant -> /usr/share/ant/bin/ant $ ls -la /usr/share/ant lrwxr-xr-x 1 root wheel 14 Nov 11 18:04 /usr/share/ant -> java/ant-1.7.1 $ ls -la /usr/share/java/ant-1.7.1 total 40 drwxr-xr-x 8 root wheel 272 Feb 27 12:32 . drwxr-xr-x 8 root wheel 272 Nov 11 18:04 .. -rw-r--r-- 1 root wheel 15289 Feb 10 2010 LICENSE.txt -rw-r--r-- 1 root wheel 1270 Feb 10 2010 NOTICE.txt drwxr-xr-x 8 root wheel 272 Feb 10 2010 bin drwxr-xr-x 3 root wheel 102 Feb 10 2010 docs drwxr-xr-x 15 root wheel 510 Feb 10 2010 etc drwxr-xr-x 44 root wheel 1496 Feb 27 12:09 lib
Gotcha! It looks like ant is hiding inside of the default Java directory, so blowing it away is probably a bad idea. Instead we’re going to throw the new version of ant into a common directory and update the symlink.
Copying the directory is easy:
$ cp -r ~/Downloads/apache-ant-1.8.2/ /Library/Ant-1.8.2
Now we need to break the existing symlink and recreate it, pointing to our new version of Ant. You’ll need to do this as root.
$ rm /usr/share/ant $ sudo ln -s /Users/Shared/apache-ant-1.8.2 ant $ Password: ********
And when we check our version string…
$ ant -version $ Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Excellent, the update’s done and we’re on the newer version. The next step is to get the FTP task working. This is just a matter of copying the Apache Commons Net library into Ant’s classpath. If you followed the previous steps, then your Ant classpath is
$ cp ~/Downloads/commons-net-2.2/commons-net-2.2.jar /Users/Shared/apache-ant-1.8.2/lib/commons-net-2.2.jar
And that’s it! You should now be in automated deployment bliss. If you need to know how to actually use the FTP task, go check out the documentation.