Why cannot Ant taskdef cannot load a resource outside ./net

Ernelli picture Ernelli · Jan 12, 2010 · Viewed 39.2k times · Source

When declaring external ant tasks using taskdef, for instance ant-contrib, the proposed setup is to use the followin taskdef:

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

This works when antcontrib.properties is located in net/sf/antcontrib relative to the build.xml file.

But when I put it in lib/net/sf/antcontrib and changes the taskdef into

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

Ant is not able to find the properties file, it gives the error

[taskdef] Could not load definitions from resource
lib/net/sf/antcontrib/antcontrib.properties. It could not be found.

It seems like ant treats the lib directory separately and fails to load a taskdef resource from there.

Answer

gmcnaughton picture gmcnaughton · Apr 1, 2010

As Alex said, you shouldn't need to unzip the jar. The <taskdef> can load antcontrib.properties directly out of the jar.

The error you got is because you changed the resource path, but the path to the file inside the compressed jar/zip is still the same. The taskdef isn't paying attention to the properties file you moved because the <classpath> you provided to <taskdef> tells it to only look in the jar.