ant - 元素 "ivy"的前缀 "ivy:cachepath"未绑定(bind)

标签 ant ivy

我已经从链接下载了 build.xml -> IVY Build link ,当我运行 ant target 时,出现以下错误:

\build.xml:92: The prefix "ivy" for element "ivy:cachepath" is not bound.



build.xml 文件:
<!--

   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.    
-->
<project name="go-ivy" default="go">
<!--

        this build file is a self contained project: it doesn't require anything else 
        that ant 1.6.2 or greater and java 1.4 or greater properly installed.

        It is used to showcase how easy and straightforward it can be to use Ivy.

        This is not an example of the best pratice to use in a project, especially
        for the java source code "generation" :-) (see generate-src target)

        To run copy this file in an empty directory, open a shell or a command window
        in this directory and run "ant". It will download ivy and then use it to resolve 
        the dependency of the class which is itself "contained" in this build script.

        After a successful build run "ant" again and you will see the build will be
        much faster.

        More information can be found at http://ant.apache.org/ivy/

-->

<!--
 here is the version of ivy we will use. change this property to try a newer 
         version if you want 
-->
<property name="ivy.install.version" value="2.0.0-beta1"/>
<property name="ivy.jar.dir" value="${basedir}/ivy"/>
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>
<property name="build.dir" value="build"/>
<property name="src.dir" value="src"/>

<target name="download-ivy" unless="skip.download">
<mkdir dir="${ivy.jar.dir}"/>
<!--
 download Ivy from web site so that it can be used even without any special installation 
-->
<echo message="installing ivy..."/>
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true"/>
</target>
<!--
 ================================= 
          target: install-ivy         
            this target is not necessary if you put ivy.jar in your ant lib directory
            if you already have ivy in your ant lib, you can simply remove this
            target and the dependency the 'go' target has on it
         ================================= 
-->
<target name="install-ivy" depends="download-ivy" description="--> install ivy">
<!--
 try to load ivy here from local ivy dir, in case the user has not already dropped
              it into ant's lib dir (note that the latter copy will always take precedence).
              We will not fail as long as local lib dir exists (it may be empty) and
              ivy is in at least one of ant's lib dir or the local lib dir. 
-->
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<!--
 ================================= 
          target: go
                    Go ivy, go!
         ================================= 
-->
<target name="go" depends="install-ivy, generate-src" description="--> resolve dependencies, compile and run the project">
<echo message="using ivy to resolve commons-lang 2.1..."/>
<!--
 here comes the magic line: asks ivy to resolve a dependency on 
             commons-lang 2.1 and to build an ant path with it from its cache  
-->
<ivy:cachepath organisation="commons-lang" module="commons-lang" revision="2.1" pathid="lib.path.id" inline="true"/>
<echo message="compiling..."/>
<mkdir dir="${build.dir}"/>
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="lib.path.id"/>
<echo>  
</echo>
<java classname="example.Hello">
<classpath>
<path refid="lib.path.id"/>
<path location="${build.dir}"/>
</classpath>
</java>
</target>
<!--
 ================================= 
          target: generate-src
            'Generates' the class source. It actually just echo a simple java 
            source code to a file. In real life this file would already be
            present on your file system, and this target wouldn't be necessary.
         ================================= 
-->
<target name="generate-src">
<mkdir dir="${src.dir}/example"/>
<echo file="${src.dir}/example/Hello.java">
package example;
import org.apache.commons.lang.WordUtils;
public class Hello {
    public static void main(String[] args) {
        String  message = "hello ivy !";
        System.out.println("standard message : " + message);
        System.out.println("capitalized by " + WordUtils.class.getName() 
                                + " : " + WordUtils.capitalizeFully(message));
    }
}        
</echo>
</target>
<!--
 ================================= 
          target: clean              
         ================================= 
-->
<target name="clean" description="--> clean the project">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${src.dir}"/>
<fileset dir="${build.dir}"/>
</delete>
</target>
<!--
 ================================= 
          target: clean-ivy              
         ================================= 
-->
<target name="clean-ivy" description="--> clean the ivy installation">
<delete dir="${ivy.jar.dir}"/>
</target>
<!--
 ================================= 
          target: clean-cache              
         ================================= 
-->
<target name="clean-cache" depends="install-ivy" description="--> clean the ivy cache">
<ivy:cleancache/>
</target>
</project>

这里有什么问题?当我尝试在 IE 中打开 build.xml 文件时,它会给出错误消息:
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. 
--------------------------------------------------------------------------------    
The operation completed successfully. Error processing resource 'file:///C:/ivy/build.xml'. Line 92, Position 117 

<ivy:cachepath organisation="commons-lang" module="commons-lang" revision="2.1" pathid="lib.path.id" inline="true"/>

最佳答案

您需要注册/绑定(bind) ivy 前缀:

<project name="go-ivy" xmlns:ivy="antlib:org.apache.ivy.ant">

以下来自 Apache Ivy 的文档 (http://ant.apache.org/ivy/history/latest-milestone/ant.html):

If you use ant version 1.6.0 or superior, you just have to add ivy namespace to your project (xmlns:ivy="antlib:org.apache.ivy.ant" attribute of your project tag), and you can call ivy tasks.

关于ant - 元素 "ivy"的前缀 "ivy:cachepath"未绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5742297/

相关文章:

android - Eclipse 不构建项目,或者构建时间太长

eclipse - 将 Gradle 与 Ivy 和 eclipse 的源相结合

ant - antrun 插件使用的是哪个版本的 ANT

java - Ant 不构建第二个 jar

java - SFTP 存储库和 SftpException

java - 关于一个好的 Java 构建工具的建议,与 Eclipse 很好地集成

sbt - 用 SBT 0.13 中的 project.properties 替换 externalIvyFile 中的属性占位符?

Apache Ivy 术语和歧义

ant - gradle什么时候以及如何解决其依赖关系?

java - Ant 项目包含多个要构建的文件夹