Installing FTP task on Ant 1.8.X on MacOSX


I recently had to reinstall the OS on the laptop I use primarily for work. I thought I had installed everything I needed, but realized that I couldn't run the FTP task in Ant because of missing libraries. The message I received was:

Problem: failed to create task or type ftp
Cause: the class was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-a directory added on the command line with the -lib argument

Do not panic, this is a common problem.
The commonest cause is a missing JAR.

This is not a bug; it is a configuration problem

My searches on the subject lead to multiple solutions, but they were aimed at earlier versions of Ant (1.7.X and below), somewhat complicated and turned out not to be what I needed for my version of Ant (1.8.1 on MacOSX 10.6.5). You'll see lots of instructions for setting your ANT_HOME environment variable, along with other settings, but that's not necessary with newer versions of Ant on MacOSX.

Most information I found on the web correctly pointed out that according to the Apache Ant install instructions for optional tasks, such as FTP, you need to have the Jakarta Oro 2.0.8 (text manipulation) and Commons-Net 2.0 (networking protocol support) jar libraries installed.

What wasn't clear is that you also need to have ant-commons-net.jar installed. However, by default, the version of Ant that is installed via the MacOSX Developer Tools does not provide that library. So, even if you install Jakarta-Oro and Commons-Net, you'll still get the missing libraries error above. If you look in the ant/lib directory, all you'll see if ant-commons-net.pom, which is a Maven support file, but not the necessary jar file.

A handy command to show you what's installed or not in your version of ant is:
> ant -diagnostics

That generates a long list of features, installed jars, version numbers, etc. When I ran it, I confirmed that the FTP task was not available:
 Tasks availability
ftp : Not Available (the implementation class is not present)

This was after I had installed Oro and Commons-Net. The phrase 'implementation class is not present' stuck out at me and I realized that ant-commons-net.jar contained the ftp implementation class, which in turn uses Oro and Commons-Net to support ftp'ing.

That said...

 Here's how to install everything:
  • Find your ant/lib directory. Any jars placed in here are available to Ant at launch. The command 'whereis' or 'which' tells you where the executable of a command is located:

    > whereis ant
    > /usr/bin/ant

    If you then do 'ls -la /usr/bin/ant' you'll see that on MacOSX that path is usually a symbolic link to /usr/share/ant.

    > ls -la /usr/bin/ant
    > lrwxr-xr-x  1 root  wheel  22 Nov 13 17:54 /usr/bin/ant -> /usr/share/ant/bin/ant

    Ant the lib directory, which is where you will place your jar files, is located at /usr/share/ant/lib.
  • Download the Jakarta-Oro 2.0.8 and Commons-Net 2.0 jars and copy them to your ant/lib directory: /usr/share/ant/lib. (It's easiest to download the zip version of binaries, btw) Ex:

    > sudo cp /path/to/jakarta-oro-2.0.8.jar /usr/share/ant/lib
    > sudo cp /another/path/commons-net-2.0.jar /usr/share/ant/lib

    You need to use 'sudo' since you need root permissions to copy files into the ant/lib directory.
  • Confirm your version of ant:
    > ant -version
    > Apache Ant version 1.8.1 compiled on September 21 2010


    > ant -diagnostics
    > ------- Ant diagnostics report -------
    Apache Ant version 1.8.1 compiled on September 21 2010
  • Download a full/complete copy of the version of Ant you have installed. I downloaded a copy from the Apache Software Foundation mirror download site. I downloaded [MIRROR_SITE]/ant/binaries/
  • Unzip full Ant installation, then copy ant-commons-net.jar to your ant/lib directory. Ex:
    > sudo cp ~/Downloads/apache-ant-1.8.1/lib/ant-commons-net.jar /usr/share/ant/lib
 Once you have the jars in place your Ant scripts which use the 'ftp' task will work.