我有以下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无法找到常春藤,即使常春藤罐位于默认的~/.ant/lib
位置并且必须明确告知在所述位置寻找它?
更新:似乎只有Ant 1.7.1才需要上述元素。对于Ant 1.8.2或Ant 1.9.4,我不必添加它。