简体   繁体   中英

Does a recursive Ant task exist to recover properties from external file?

I ve got a problem in getting properties with ant from a properties file. With a simple target like this in my build.xml, i'd like to get at least two properties path1 and path2. I'd like to have a generic target to get this two properties.... in order to avoid modifying the build.xml (just adding a new prop)

Any suggestions? Thanks in advance !

build.xml :

<target name="TEST" description="test ant">
    <property file="dependencies.properties"/>  
    <svn>  
        <export srcUrl="${path.prop}" destPath="${workspace}/rep/" />  
    </svn>  
</target>  

dependencies.properties :

path1.prop = /path/to/src1
path2.prop = /path/to/src2

Thanks, it works. in addition you can use the propertycopy from ant-contrib to get other properties from the file.

dependencies.list=path1,path2
path1.prop1=val1
path1.prop2=val2
path2.prop1=val3
path2.prop2=val4

like this :

<target name="main">
    <property file="dependencies.properties"/>
    <foreach list="${dependencies.list}" delimiter="," param="name" target="doExtract" inheritall="true"/>
</target>

<target name="doExtract">
    <propertycopy name="prop1" from="${name}.prop1" silent="true"/>
    <propertycopy name="prop2" from="${name}.prop2" silent="true"/>
    <svn>
        <export srcUrl="${prop1}" destPath="${workspace}/rep/"" />
    </svn>
</target>

您可以将路径设置写到单个属性中的逗号分隔列表中,并使用foreach循环

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM