How To Install ANT-Contrib

Published: {ts '2012-07-10 00:00:00'}
Author: Steven Neiland
Site Url: http://www.neiland.net/article/how-to-install-ant-contrib/

While ANT comes with many great features out of the box. Eventually you will need some additional task capabilities that are not available as standard. Fortunately it is very easy to include third party tasks that others have already written.

The most common set of third party tasks which get installed are the ANT-Contrib tasks. These tasks add additional logic and decision making capabilities such as looping which are invaluable for larger projects.

Step 1: Get ANT-Contrib And Install It

So lets get started installing them. Go to the ant-contrib download page on sourceforge and get the 1.0b3 version zip file. Extract the zip file and copy "ant-contrib-1.0b3.jar" to your "{ant install dir}/lib" folder.

Step 2: Configure Your Project

With the jar file installed in the ant lib directory the next step is to include the ant-contrib tasks in your project. To do this add a taskdef entry to your build file init code. The format of this depends on the version of ant you are running.

Ant >= 1.6

Ant < 1.6

Step 3 (optional): Add To Eclipse

If you use ANT in an IDE such as eclipse you need to add a reference to the ant-contrib jar file in the classpath config. To do this in eclipse open the Window menu and select:

Window -> Preferences -> Ant -> Runtime -> Classpath -> Add External JARs -> Global Entries

Browse to the ant-contrib jar file on your hard drive and select it. Apply the changes and close the settings window.

Step 4: Test

Finally at this stage you should be able to use the new ant-contrib tasks so lets test it. Add a new test task to your build file and call one of the new ant-contrib tasks from it. Below is the test I normally use to check ant-contrib is working using the for list loop task.

Letter @{letter}