我有以下 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
文件中 . 添加此元素后,构建成功 .
为什么Ant无法找到Ivy,即使Ivy jar位于默认的 ~/.ant/lib
位置并且必须明确告知在所述位置查找它?
Update :似乎上述元素只是Ant 1.7.1所必需的 . 对于Ant 1.8.2或Ant 1.9.4,我不必添加它 .
1 回答
这是由于构建文件中的XML名称空间声明:
xmlns:ivy="antlib:org.apache.ivy.ant"
由于正在使用前缀
ivy:
,因此taskdef
任务中需要uri
属性以允许使用前缀调用任务:typedef文档中显示了一个示例:
EDIT:
antlib表示如果antlib放在Ant的主目录中,默认情况下Ant可以加载正确的资源: