Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache ant does not recognize 'for' task/macro, although I have added ant-contrib via taskdef

Tags:

build

ant

I am getting following while doing ant build:

Build\build.xml:247: Problem: failed to create task or type
for
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

build.xml line 247 is <for param="file">

Already defined <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>, it didn't work. Then I specifically added following but it is still not working.

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="${env.ANT_HOME}/lib/ant-contrib-1.0b3.jar"/>
        </classpath>
    </taskdef>

I have ant-contrib-1.0b3.jar at C:\Softwares\apache-ant-1.8.4\lib directory.
What is missing here?

like image 530
Himanshu Yadav Avatar asked Sep 13 '12 13:09

Himanshu Yadav


People also ask

What is the use of ant contrib jar?

The Ant-Contrib project is a collection of user supplied task (like an <if> task) and a development playground for experimental tasks like a C/C++ compilation task for different compilers.

What is Macrodef in ant?

This is used to specify attributes of the new task. The values of the attributes get substituted into the templated task. The attributes will be required attributes unless a default value has been set.

What is Antlib?

Description. An antlib file is an xml file with a root element of antlib . Antlib's elements are Apache Ant definition tasks—like Taskdef or any Ant task that extends org. apache. tools.


1 Answers

If you placed the AntContrib jar in $ANT_HOME/lib directory, all you really need to do is this:

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

Actually to use the <for/> task, you need to do this:

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

Note you have to use antlib.xml and not antcontrib.properties. Read the Installation directions very carefully. It's easy to miss.

If you are doing this in a group project, I recommend that you put your ant-contrib.jar in your project. THen add them to your project in your version control system. That way, other developers can use your build with the ant-contrib tasks without downloading the ant-contrib jar and installing it in their $ANT_HOME directory themselves.

Let's say you create a directory called ant-contrib.dir and put that in the root of your project, then put the ant-contrib jar in that folder. Just put this in your project:

<taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
          <fileset dir="${basedir}/ant-contrib.dir"/>
    </classpath>
</taskdef>
like image 94
David W. Avatar answered Nov 05 '22 00:11

David W.