使用Ant嵌套for和属性

时间:2013-10-06 10:43:12

标签: ant

我有10个属性文件列表说1.properties , 2 .pro ....10.properties 另一个名为total.properties的文件,其中包含所有文件属性名称。

现在问题是打印total.properies文件中提到的所有文件内容 使用ant脚本。

Eg:
1.properties
name:rajesh
languesknown:en,sp
2.properties
name:kumar
languesknown:en,fr,wd

total.properties
numbers: 1,2

output:
name:rajesh
languesknown:en,sp
name:kumar
languesknown:en,fr,wd

使用蚂蚁脚本。

我试过

但每次打印第一个记录,即1.properties但其迭代次数取决于总属性中的内容没有。任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

ANT不是脚本语言。最好的方法是嵌入脚本语言。以下示例使用Groovy

实施例

├── build.xml
└── src
    ├── 10.properties
    ├── 1.properties
    ├── 2.properties
    ├── 3.properties
    ├── 4.properties
    ├── 5.properties
    ├── 6.properties
    ├── 7.properties
    ├── 8.properties
    ├── 9.properties
    └── total.properties

的build.xml

<project name="demo" default="print-properties">

   <target name="bootstrap">
      <mkdir dir="${user.home}/.ant/lib"/>
      <get dest="${user.home}/.ant/lib/groovy-all.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.1.7/groovy-all-2.1.7.jar"/>
   </target>

   <target name="print-properties">
      <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
      <groovy>
         new File("src/total.properties").eachLine {
            def props = new File("src/${it}")

            println props.name
            println props.text
         }
      </groovy>
   </target>

</project>

注释

  • “bootstrap”目标安装groovy任务jar
  • 该脚本读取“total.properties”文件的每一行,然后打印找到的每个文件名的名称和内容。
相关问题