1
votes

I am running into the following error when trying to run ant:

Problem: failed to create task or type runtarget

I am building on a mac 10.8.3.

Prior research has suggested that I add ant-contrib-0.3.jar to my ANT_HOME installation directory, which I have done (that had actually gotten rid of another 'failed to create task or type' error)

I used ant-contrib-0.3.jar because research suggested that this jar is mapped to the line:

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

which is in the build.xml file I am using.

The project builds on windows machines ( I even got it to build using https://code.google.com/p/winant/ ) but am trying to get it built on a mac. I am thus not looking to change the build.xml file.

An example of the run target line is:

<target name="setPASProps" depends="" description="setup the properties">
    <property name="systemname" value="PAS"/>
    <runtarget target="setSystemProps"/>
</target> 

Here is some info from running ant -diagnostics

-------------------------------------------
 ANT PROPERTIES
-------------------------------------------
ant.version: Apache Ant(TM) version 1.8.2 compiled on June 20 2012
ant.java.version: 1.7
Is this the Apache Harmony VM? no
Is this the Kaffe VM? no
Is this gij/gcj? no
ant.core.lib: /usr/share/ant/lib/ant.jar
ant.home: /usr/share/ant
-------------------------------------------
 ANT_HOME/lib jar listing
-------------------------------------------
ant.home: /usr/share/ant
ant-antlr.jar (5756 bytes)
ant-contrib-0.3.jar (17708 bytes)
ant-jmf.jar (6745 bytes)
ant-junit.jar (102350 bytes)
ant-junit4.jar (7126 bytes)
ant-launcher.jar (12321 bytes)
ant-swing.jar (7563 bytes)
ant-testutil.jar (15198 bytes)
ant.jar (1937098 bytes)

Thanks !

2

2 Answers

0
votes

It would be helpful if you posted your build.xml too.

You usually get this error if Ant sees a task, but there's a problem with the definition.

Here's my recommendation:

  • In your project create a directory antlib/ant-contrib.
  • Download this zip file. Ant-contrib is a wee bit strange is that there is a separate jar for C compiling and for all of the other Ant tasks. The latest version is 1.0b3. When you unzip this zip file, you will see ant-contrib-1.0b3.jar inside this folder.
  • Put that ant-contrib-1.0b3.jar inside the antlib/ant-contrib folder.

Now, in your build.xml, use the following <taskdef/>:

<taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
        <fileset dir="${basedir}/antlib/ant-contrib"/>
    </classpath>
</taskdef>

Make sure this is not inside a target. You want this to be executed before any targets are executed.

I like doing the definition this way because the Ant Contrib jar file becomes part of my project, and anyone who needs to run my project will not have to manually install the Ant Contrib jar before they can use my project.

Take a look at your build.xml and see where that <Runtarget> task is being used. I've never used it, and the documentation for this task is so clear and helpful. Actually, I'm not even sure if it works. If you are still having problems, you try to see if you can remove the defined <target/> that contains this task, and see if that gets rid of the issue.

0
votes

Removed ant-contrib-0.3.jar and added ant-contrib-1.0b3.jar and ant-contrib.jar to my ANT_HOME directory since these are the jars installed with https://code.google.com/p/winant/ (and it was working on windows machines).

This did the trick.