gpt4 book ai didi

尽管 jar 在 ~/.ant/lib 中,但 Ant 找不到 Ivy jar

转载 作者:行者123 更新时间:2023-12-04 14:33:25 24 4
gpt4 key购买 nike

我有以下 build.xml 只是为了演示问题:

<project
xmlns:ivy="antlib:org.apache.ivy.ant"
name="test" default="test-ivy">
<target name="test-ivy">
<ivy:settings />
</target>
</project>

使用 Ant (1.7.1) 调用它时,我得到:

$ ant
Buildfile: build.xml

test-ivy:

BUILD FAILED
/home/voops/test/build.xml:7: Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-/usr/share/ant/lib
-/home/voops/.ant/lib
-a directory added on the command line with the -lib argument


Total time: 0 seconds

但是 Ivy jar 确实存在于我的 ~/.ant/lib 目录中:

$ whoami
voops
$ls /home/voops/.ant/lib/ivy-2.3.0.jar
-rw-rw-r-- 1 voops voops 1222059 Nov 11 14:55 /home/voops/.ant/lib/ivy-2.3.0.jar

看来我必须通过添加以下元素手动指示 Ivy jar 所在的位置:

<taskdef uri="antlib:org.apache.ivy.ant" resource="org/apache/ivy/ant/antlib.xml"  classpath="${user.home}/.ant/lib/ivy-2.3.0.jar"/> 

... 在我的 build.xml 文件中。添加此元素后,构建成功。

为什么即使 Ivy jar 位于默认的 ~/.ant/lib 位置并且必须明确告知要在所述位置寻找它,Ant 还是找不到 Ivy?

更新:上面的元素好像只有Ant 1.7.1才需要。对于 Ant 1.8.2 或 Ant 1.9.4,我不必添加它。

最佳答案

这是由于构建文件中的 XML 命名空间声明:

xmlns:ivy="antlib:org.apache.ivy.ant"

由于前缀 ivy: 被使用,uri 属性需要在 taskdef 任务中允许调用带有前缀的任务:

typedef 中显示了一个示例文档:

uri: The uri that this definition should live in. since Ant 1.6

编辑:

antlib表示如果antlib放在Ant的主目录下,Ant默认可以加载正确的资源:

When Ant encounters a element with a namespace URI with this pattern, it will check to see if there is a resource of the name antlib.xml in the package directory in the default classpath.

关于尽管 jar 在 ~/.ant/lib 中,但 Ant 找不到 Ivy jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26929133/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com