0

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

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

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 但它的迭代两次取决于总属性中没有内容。那么有人可以帮忙吗?

4

1 回答 1

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

构建.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>

笔记

  • “引导”目标安装 groovy 任务 jar
  • 该脚本读取“total.properties”文件的每一行,然后打印找到的每个文件名的名称和内容。
于 2013-10-06T20:56:39.270 回答