copy不支持Ant-contrib嵌套循环中的嵌套"if"元素



如果存在DML.sql文件,我需要将所有dml.sql文件复制到DB2_List.txt文件内部。但是在执行此文件后,我收到这样的错误:copy 不支持嵌套的"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>
有可能

实现你所追求的,你只需要在 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>

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

 <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>

最新更新