【问题标题】:copy a file in ant based on condition根据条件在ant中复制文件
【发布时间】:2014-01-26 10:49:34
【问题描述】:

如果在 ant 目标中设置了属性,我必须复制一个文件,但我总是收到此代码的错误:

<condition property="component.is.x">
  <equals arg1="${COMPONENT_ID}" arg2="x" />
</condition>
<target name="copyschemaparamsfile" if="sql.file.present" >
  <if>
    <equals arg1="${component.is.x}" arg2="true" />
    <then>
      <copy file="${in.root}/schema/${COMPONENT_ID}-schema.sql"
            tofile="${tmp.dir}/${COMPONENT_ID}/x/schema/schema.sql" 
            failonerror="false" />
    </then>
    <else>
      <copy file="${inf.root}/schema/${COMPONENT_ID}-schema.sql"
            tofile="${tmp.dir}/${COMPONENT_ID}/${COMPONENT_ID}/schema/schema.sql" failonerror="false" />
    </else>
  </if>
</target>

错误是

Ant could not find the task or a class this task relies upon.
This is common and has a number of causes; the usual
    solutions are to read the manual pages then download and
    install needed JAR files, or fix the build file:
     - You have misspelt 'if'.
       Fix: check your spelling.
     - The task needs an external JAR file to execute
         and this is not found at the right place in the classpath.
       Fix: check the documentation for dependencies.
       Fix: declare the task.
     - The task is an Ant optional task and the JAR file and/or libraries
         implementing the functionality were not found at the time you
         yourself built your installation of Ant from the Ant sources.
       Fix: Look in the ANT_HOME/lib for the 'ant-' JAR corresponding to the
         task and make sure it contains more than merely a META-INF/MANIFEST.MF.
         If all it contains is the manifest, then rebuild Ant with the needed
         libraries present in ${ant.home}/lib/optional/ , or alternatively,
         download a pre-built release version from apache.org
     - The build file was written for a later version of Ant
       Fix: upgrade to at least the latest release version of Ant
     - The task is not an Ant core or optional task
         and needs to be declared using <taskdef>.
     - You are attempting to use a task defined using
        <presetdef> or <macrodef> but have spelt wrong or not
       defined it at the point of use

    Remember that for JAR files to be visible to Ant tasks implemented
    in ANT_HOME/lib, the files must be in the same directory or on the
    classpath

我在执行时总是遇到错误。有人可以建议如何在 ant 目标中检查参数并从一个目录复制到另一个目录吗?

【问题讨论】:

    标签: java xml eclipse ant jar


    【解决方案1】:

    Ant &lt;if/&gt;Ant-Contrib 的一部分。要使用,请按照Ant-Contrib Tasks installation page 上的说明进行操作:

    (1) 将ant-contrib-0.3.jar复制到你的Ant的lib目录下 安装。如果您想在自己的项目中使用其中一项任务, 添加行

    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
    

    到您的构建文件。

    (2) 将 ant-contrib-0.3.jar 保存在单独的位置。你现在必须 明确告诉 Ant 在哪里可以找到它(比如在 /usr/share/java/lib 中):

    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
      <classpath>
        <pathelement location="/usr/share/java/lib/ant-contrib-0.3.jar"/>
      </classpath>
    </taskdef>
    

    【讨论】:

    • 嗨,感谢您的回复。我做了和 1)(1) 一样的操作,将 ant-contrib-0.3.jar 复制到你 Ant 安装的 lib 目录下。如果您想在自己的项目中使用其中一项任务,请将 行添加到您的构建文件中。但错误还是一样。
    • 找不到 Ant-Contrib JAR 文件。例如,您可能已经将它放在了 ant 安装的 lib/ 目录中,而不是您正在调用的那个。仔细检查错误消息中的每个建议,这些建议非常全面。如果所有这些都失败了,请尝试其他 (2) 方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 2015-10-11
    • 2021-09-01
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多