为什么Ant taskdef无法加载./net之外的资源

Ern*_*lli 11 ant taskdef

当使用taskdef声明外部ant任务时,例如ant-contrib,建议的设置是使用followin taskdef:

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
  <classpath>
    <pathelement location="lib/ant-contrib/ant-contrib-1.0b3.jar"/>
  </classpath>
</taskdef>
Run Code Online (Sandbox Code Playgroud)

当antcontrib.properties位于net/sf/antcontrib相对于build.xml文件时,这种方法有效.

但是当我把它放在lib/net/sf/antcontrib中并将taskdef更改为

<taskdef resource="lib/net/sf/antcontrib/antcontrib.properties">
  <classpath>
    <pathelement location="lib/ant-contrib/ant-contrib-1.0b3.jar"/>
  </classpath>
</taskdef>
Run Code Online (Sandbox Code Playgroud)

Ant无法找到属性文件,它会给出错误

[taskdef] Could not load definitions from resource
lib/net/sf/antcontrib/antcontrib.properties. It could not be found.
Run Code Online (Sandbox Code Playgroud)

似乎ant分别处理lib目录并且无法从那里加载taskdef资源.

gmc*_*ton 5

正如亚历克斯所说,你不应该解开罐子.该<taskdef>可直接加载antcontrib.properties出罐.

您得到的错误是因为您更改了资源路径,但压缩jar/zip中文件的路径仍然相同.taskdef没有注意你移动的属性文件,因为<classpath>你提供的文件<taskdef>告诉它只能查看jar.