【问题标题】:nested for and properties using Ant使用 Ant 嵌套 for 和属性
【发布时间】:2013-10-06 10:43:11
【问题描述】:

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

使用 ant 脚本。

我试过了

但是每次它的打印第一条记录即 1.properties 但它的迭代两次取决于总属性中没有内容。那么有人可以帮忙吗?

【问题讨论】:

    标签: ant


    【解决方案1】:

    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”文件的每一行,然后打印找到的每个文件名的名称和内容。

    【讨论】:

      猜你喜欢
      • 2017-09-10
      • 2013-01-02
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多