为什么 Ant taskdef 无法加载 ./net 之外的资源
当使用taskdef声明外部ant任务时,例如ant-contrib,建议的设置是使用以下taskdef:
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="lib/ant-contrib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
当antcontrib.properties位于相对于build.xml文件的net/sf/antcontrib中时,这有效。
但是当我将其放入 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>
Ant 无法找到属性文件时,它会给出错误
[taskdef] Could not load definitions from resource
lib/net/sf/antcontrib/antcontrib.properties. It could not be found.
看起来 ant 单独处理 lib 目录并且无法从那里加载 taskdef 资源。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如亚历克斯所说,你不需要解压罐子。
可以直接从 jar 中加载 antcontrib.properties。您得到的错误是因为您更改了资源路径,但压缩的 jar/zip 内文件的路径仍然相同。 taskdef 不会关注您移动的属性文件,因为您提供给
的
告诉它只在 jar 中查找。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.使用
antlib.xml
资源:这是我使用的 taskdef 定义:
您不需要从 jar 文件中提取任何内容。此外,如果您不想在 antcontrib 任务中使用命名空间,则
uri
属性是可选的。Use
antlib.xml
resource:Here is the taskdef definition that I use:
You do not need to extract anything from the jar file. Also,
uri
attribute is optional if you do not want to use namespaces with antcontrib tasks.为了处理任务定义的类路径,我在 Ant 中使用类路径引用,这更容易。您可以链接包含类的目录,或者包含许多 .jar 的目录,或者(当然)单个 .jar。
例如 :
To handle classpath for tasks definitions, I use a classpath ref in Ant, it's way easier. You can link either a directory containing classes, either a directory containing many .jar, either (of course) a single .jar.
For example :