简体   繁体   English

如何在我的Ant构建中修复“Unexpected element”{}目标“{antlib:org.apache.tools.ant} target”错误?

[英]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.

相关问题 意外元素“{http://maven.apache.org/POM/4.0.0}project”{antlib:org.apache.tools.ant}project - Unexpected element &quot;{http://maven.apache.org/POM/4.0.0}project&quot; {antlib:org.apache.tools.ant}project 如果findBugs目标发现错误,如何使我的Ant构建失败 - How to fail my Ant build if findBugs target find bugs 如何在Ant中重新定义目标? - How to redefine target in Ant? 有没有办法推广Apache ANT目标? - Is there a way to generalize an Apache ANT target? “无法在Ant中创建任务或输入antlib:org.apache.maven.artifact.ant:mvn”错误 - “Failed to create task or type antlib:org.apache.maven.artifact.ant:mvn” error in Ant 如何修复Java lang.ClassNotFoundException:org.apache.tools.ant.taskdefs.Execute - How to fix java lang.ClassNotFoundException: org.apache.tools.ant.taskdefs.Execute Apache Ant java 目标中的 maxmemory 标志到底是做什么的? - What does maxmemory flag in Apache Ant java target exactly do? 如何满足:Import org.apache.tools.ant.BuildException; - How to satisfy: Import org.apache.tools.ant.BuildException; 如何在其他构建文件目标中导入一个蚂蚁构建文件 - how to import an ant build file inside other build file target 使用Ant构建当前构建目标的依赖关系 - Using Ant to build dependencies of the current build target
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM