【问题标题】:Ant failing to find Ivy jar although jar is in ~/.ant/lib尽管 jar 在 ~/.ant/lib 中,但 Ant 未能找到 Ivy jar
【发布时间】:2015-01-11 19:03:06
【问题描述】:

我有以下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,我不必添加它。

【问题讨论】:

  • 我在 MacOSX (10.11.6 El Capitan) 上遇到了类似的问题。我用 Brew 包管理器安装了 ant 和 Ivy。另一种方法是使用 -lib 选项手动定义它,例如:ant clean compile -lib /usr/local/Cellar/ivy/2.4.0/libexec/ivy-2.4.0.jar

标签: ant ivy


【解决方案1】:

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

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

由于使用了前缀ivy:,因此taskdef 任务中需要uri 属性以允许调用具有前缀的任务:

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

uri:这个定义应该存在的uri。从Ant 1.6开始

编辑:

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

当 Ant 遇到一个具有这种模式的命名空间 URI 的元素时,它会检查默认类路径下的包目录中是否存在名为 antlib.xml 的资源。

【讨论】:

  • 是的,但完全相同的 build.xml 可以在 Ant 1.8.2 中正常工作,并且该版本的 Ant 不需要 taskdef。此外,错误消息似乎抱怨~/.ant/lib 中不存在实现库,而实际上它确实存在。
  • 您可能想看看this page。据我所知,如果 antlib 在本地 Ant 安装中,则不需要 taskdef。您的 ~/.ant/ 目录是否包含 1.7.1 或 1.8.2 的安装?
  • 我的~/.ant 目录包含一个目录:lib,在该lib 目录内有一个jar:ivy-2.3.0.jar。
猜你喜欢
  • 2018-02-24
  • 1970-01-01
  • 1970-01-01
  • 2015-06-18
  • 2011-06-26
  • 1970-01-01
  • 2018-02-15
  • 2012-04-24
  • 2010-10-31
相关资源
最近更新 更多