0

如果存在 DML.sql 文件,我需要将所有 dml.sql 文件复制到 DB2_List.txt 文件中。但是在执行这个文件之后,我得到了这样的错误:复制不支持嵌套的“if”元素。

如果您对 Ant 中的嵌套循环有更好的了解,请告诉我。

<available file="DB/DML.sql" property="db.check.present"/>
<copy file="DB/DDL.sql" tofile="DB2/DB2_List.txt" >
<if> 
 <equals arg1="${db.check.present}" arg2="true"/>
 <then> 
 <filterchain> 
    <concatfilter append="DB/DML.sql" /> 
    <tokenfilter delimoutput="${line.separator}" /> 
</filterchain> 
</then> 
</if> 
</copy>
4

2 回答 2

3

有可能实现你所追求的,你只需要在 Ant 中以完全不同的方式处理它。请注意,您将需要使用单独的目标。

<target name="db.check">
  <available file="DB/DML.sql" property="db.check.present"/>
</target>
<target name="db.copy" depends="db.check" if="db.check.present">
  <copy file="DB/DDL.sql" tofile="DB2/DB2_List.txt" >
    <filterchain> 
      <concatfilter append="DB/DML.sql" /> 
      <tokenfilter delimoutput="${line.separator}" /> 
    </filterchain> 
  </copy>
</target>
于 2013-10-03T13:20:54.513 回答
2

看看 Ant 1.9.1,它支持标签上的特殊if/unless属性。这可能是可能的:

 <project name="mysterious.moe" basedir="."  default="package"
    xmlns:if="ant:if"
    xmlns:unless="ant:unless"/>

    <target name="db.copy">
        <available file="DB/DML.sql" property="db.check.present"/>
        <copy file="DB/DDL.sql" 
            tofile="DB2/DB2_List.txt">
            <filterchain if:true="db.ceck.present"> 
                <concatfilter append="DB/DML.sql" /> 
                <tokenfilter delimoutput="${line.separator}" /> 
            </filterchain> 
       </copy>
    <target>
...
</project>

否则,您将不得不使用两个单独的副本。您不能将<if>antcontrib 放入任务中。仅围绕任务:

<available file="DB/DML.sql" property="db.check.present"/>
<if> 
    <equals arg1="${db.check.present}" arg2="true"/>
    <then> 
        <copy file="DB/DDL.sql" tofile="DB2/DB2_List.txt" >
            <filterchain> 
                <concatfilter append="DB/DML.sql" /> 
                <tokenfilter delimoutput="${line.separator}" /> 
            </filterchain>
        </copy>
        </then>
        <else>
            <copy file="DB/DDL.sql" tofile="DB2/DB2_List.txt" >
        </else>
    </if> 
</copy>
于 2013-10-03T14:52:48.347 回答