[英]How do I fix 'Unexpected element “{}target” {antlib:org.apache.tools.ant}target' errors in my Ant build?
When I run my Ant build it fails with the following exception: 当我运行我的Ant构建时,它失败并出现以下异常:
Unexpected element "{}target" {antlib:org.apache.tools.ant}target
I'm using Eclipse 3.4.2. 我正在使用Eclipse 3.4.2。
Please let me know what I'm missing here. 请让我知道我在这里缺少什么。
I can reproduce this problem by putting a target
outside the project
element that is required in ant build files. 我可以通过将
target
置于ant构建文件中所需的project
元素之外来重现此问题。 The error indicates that there is a fault in your build file - something (a target
element) in the wrong place. 该错误表示构建文件中存在错误 - 某些(
target
元素)位于错误的位置。
This build throws that error: 这个构建抛出了这个错误:
<?xml version="1.0"?>
<target name="wibble" />
<project name="stack_overflow">
</project>
Whereas this does not: 然而,这不是:
<?xml version="1.0"?>
<project name="stack_overflow">
<target name="wibble" />
</project>
In the full error message you should get a line number to guide you to the point in the file needing attention: 在完整的错误消息中,您应该获得一个行号,以指导您到需要注意的文件中的点:
# line number here
# v
build.xml:2: Unexpected element "{}target" {antlib:org.apache.tools.ant}target
Surprinsingly, the apache foundation doesn't clearly express the namespace in which ant scripts are to be written. 令人遗憾的是,apache基础并没有清楚地表达要编写ant脚本的命名空间。 Yet it's an important XML concept...
然而,这是一个重要的XML概念......
However, the error message you get shows this namespace URI: antlib:org.apache.tools.ant 但是,您收到的错误消息显示此命名空间URI:antlib:org.apache.tools.ant
Although most of the time you don't need to bound the default namespace, this may help in your case: 虽然大多数情况下您不需要绑定默认命名空间,但这可能对您的情况有所帮助:
<project xmlns='antlib:org.apache.tools.ant'>
<!-- ... -->
</project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.