2013-10-03 53 views
0

如果存在DML.sql文件,我需要将所有dml.sql文件复制到DB2_List.txt文件中。但执行此文件后,我得到这样的错误: 副本不支持嵌套的“if”元素。副本不支持Ant-contrib嵌套循环中嵌套的“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> 

回答

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

大卫你好,如果有四个数据库文件,我需要检查所有四个文件的可用性和基于可用性我需要从现有的文件的内容复制到一个文本文件中。例如:如果像dbddl,dbdml,normalddl和normaldml这样的四个db文件,那么我需要检查以下情况。在第一种情况下,如果有四个文件可用(存在),则从所有四个文件复制内容并粘贴到一个文本文件中。在第二种情况下,如果只有三个文件,则从所有三个文件复制内容并粘贴到文本文件中。等等。 –

+2

查看[''](http://ant.apache.org/manual/Tasks/macrodef.html)任务。你可以创建一个''宏任务来验证,如果需要的话,将db文件复制到你的文本文件中。 –