根据条件复制ant中的文件

时间:2014-01-08 11:10:28

标签: java xml eclipse ant jar

如果在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

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

1 个答案:

答案 0 :(得分:1)

Ant <if/> 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>
相关问题