gpt4 book ai didi

java - 是否存在从外部文件恢复属性的递归 Ant 任务?

转载 作者:行者123 更新时间:2023-11-30 11:59:24 25 4
gpt4 key购买 nike

我在使用 ant 从属性文件中获取属性时遇到了问题。在我的 build.xml 中有一个像这样的简单目标,我想至少获得两个属性 path1 和 path2。我想要一个通用目标来获取这两个属性....以避免修改 build.xml(只需添加一个新 Prop )

有什么建议吗?提前致谢 !

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

最佳答案

谢谢,它有效。此外,您可以使用 ant-contrib 的 propertycopy 从文件中获取其他属性。

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

像这样:

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

关于java - 是否存在从外部文件恢复属性的递归 Ant 任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2624545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com