【发布时间】: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