3
votes

I have some ant files that one imports the other. Specifically build.xml imports a project_default.xml. When I try to do a build I get following error:

Buildfile: C:\myproject\build.xml [taskdef] Could not load definitions from resource net/sf/antcontrib/antcontrib.properties. It could not be found.

BUILD FAILED C:\myproject\build.xml:14: The following error occurred while executing this line: C:\myproject\project_default.xml:17: Problem: failed to create task or type if Cause: The name is undefined. Action: Check the spelling. Action: Check that any custom tasks/types have been declared. Action: Check that any / declarations have taken place.

Line 17 that is reported is the following:

<if>   
<contains string="${env.PROJECT_SELECTION}" substring="env.PROJECT_SELECTION" />  

I also added the following in the build.xml:

<taskdef resource="net/sf/antcontrib/antcontrib.properties">  
  <classpath>  
    <pathelement location="D:\UserData\ant-contrib-0.6-bin\lib\ant-contrib-0.6.jar"/>  
  </classpath>  
</taskdef>  

But got the same error. Any idea of what is the problem here?

2

2 Answers

2
votes

with ant version > 1.6 you should use "net/sf/antcontrib/antlib.xml" instead of "net/sf/antcontrib/antcontrib.properties"

so change the taskdef to this:

<taskdef resource="net/sf/antcontrib/antlib.xml">  
  <classpath>  
    <pathelement location="D:\UserData\ant-contrib-0.6-bin\lib\ant-contrib-0.6.jar"/>  
  </classpath>  
</taskdef>  

cheers,

0
votes

The first thing to check is that you have the ant-contrib jar path corrext. Run ant with -verbose to get more info about what it's doing and what tasks it's trying to load from where.

Where did you add the taskdef? If you're using the <if> task outside a target then you need the taskdef before it, also outside a target. If you're using it inside a target then the taskdef can be (textually) after the call as long as it is either outside a target or in a target that runs before the <if> in dependency order.