score:32

Accepted answer

you can provide full path to the ant-contrib jar explicitly using "classpath" element:

<taskdef resource="net/sf/antcontrib/antlib.xml">
  <classpath>
    <pathelement location="${path-to-ant-contrib}/ant-contrib-1.0b3.jar"/>
  </classpath>
</taskdef>

edit: link contributed by djacomo:

score:0

check you have read permissions for the ant-contrib jar file.

in our case after copying the file with another user it did not, giving the same error message.

score:1

use the below mentioned code in your build xml:

<path id="ant.classpath">
<pathelement location="${ant.jarpath}/ant.jar" />
<pathelement location="${ant.jarpath}/ant-contrib-0.3.jar" />
</path>
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
 <classpath refid="ant.classpath" />
</taskdef>

and in your build property file:

ant.jarpath=d:/antjars

and place ant.jar and ant-contrib-0.3.jar in directory:d:/antjars

score:2

it would appear that you haven't installed the ant contrib jar into the correct lib directory. this can be difficult to do if you have several installations of ant.

my suggestion is to install your ant plugins into the "$home/.ant/lib" directory. you could go one step further and automate the process as follows:

<project name="ant-contrib-tasks" default="all">

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

    <target name="bootstrap">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/ant-contrib.jar" src="http://search.maven.org/remotecontent?filepath=ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
    </target>

    <target name="all">
        <for param="file">
            <fileset dir="." includes="*.txt"/>
            <sequential>
                <echo message="found file @{file}"/>
            </sequential>
        </for>
    </target>

</project>

score:6

i fixed that this way:

add the jar to the ant runtime classpath entries.

window>preferences>ant>runtime>classpath

add the jar to either ant home entries or global entries.

score:8

one important thing missing from this stackoverflow page is that setting the correct ant_home env var is absolutely vital and important, without this setting ant keeps telling the same error, regardless of where you copy the ant-contrib-1.0b3.jar on your file systems. this missing thing has costed me a few hours. =)

however i receive this error without eclipse, in the pure ant.


Related Query

More Query from same tag