How To Install ANT-Contrib

Author: Steven Neiland
Published:

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

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

<taskdef resource="net/sf/antcontrib/antlib.xml"/>

Ant < 1.6

<taskdef resource="net/sf/antcontrib/antcontrib.properties" />

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.

<echo message="Testing ant-contrib is working by looping through a list of letters."/>
<for list="a,b,c,d,e" param="letter">
      <sequential>
            <echo>Letter @{letter}</echo>
      </sequential>
</for>

Related Blog Postings

Reader Comments

Thiago Lopes's Gravatar
Thiago Lopes
Tuesday, July 17, 2012 at 9:57:33 AM Coordinated Universal Time

Thanks! This tutorial help me to solve a hard problem. Are you going to do anothers tutoriais in ant ?

Steven Neiland's Gravatar
Steven Neiland
Tuesday, July 17, 2012 at 10:58:02 AM Coordinated Universal Time

You're welcome.

I have a few drafts for ANT articles, its just a case of finding time to finish them up.

Paula Reilly's Gravatar
Paula Reilly
Friday, January 17, 2014 at 12:45:10 PM Coordinated Universal Time

Thanks so much! This solved a problem for me too!!

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain advertisments or appear to be created for the purpose of link building, will not be published.

Archives Blog Listing