gpt4 book ai didi

ant - 如何在ant中访问属性内的属性

转载 作者:行者123 更新时间:2023-12-04 03:10:16 25 4
gpt4 key购买 nike

大家好,请看一下这段代码

在我的属性文件中,我有
win-x86.pc-shared-location=E:\Ant_Scripts

现在下面我想打电话 PrintInstallerName_build来自我的 build.xml,而为 PrintInstallerName_build在 test.xml 中。在 build.xml 文件中,${platform.id} has value=win-x86在调用目标和被调用目标 param1 中也有 value=win-x86

    <target name="PrintInstallerName" >
<echo>PlatForm.Id====>${platform.id}</echo>
<ant antfile="test.xml" target="PrintInstallerName_build">
<property name="param1" value="${platform.id}"/>
</ant>


<target name="PrintInstallerName_build" >
<echo>${param1.pc-shared-location}</echo><!--${param1.pc-shared-location}-->
<echo>${param1}.pc-shared-location}</echo><!--win-x86.pc-shared-location-->
<echo>${win-x86.pc-shared-location}</echo><!--E:\\Ant_Scripts-->
</target>

正如你所看到的,只有最后一条语句给出了正确的输出,但它是硬编码的,我想使用 param1 并且输出应该是 E:\\Ant_Scripts我尝试使用 $ 和 @ 但没有任何效果,可能是我在某处做错了有人可以帮忙吗,我很震惊,明天就是它的 DOD。

最佳答案

请参见 Properties 中的大括号嵌套Ant 手册的页面。

In its default configuration Ant will not try to balance braces in property expansions, it will only consume the text up to the first closing brace when creating a property name. I.e. when expanding something like ${a${b}} it will be translated into two parts:

the expansion of property a${b - likely nothing useful.
the literal text } resulting from the second closing brace

This means you can't use easily expand properties whose names are given by properties, but there are some workarounds for older versions of Ant. With Ant 1.8.0 and the the props Antlib you can configure Ant to use the NestedPropertyExpander defined there if you need such a feature.

关于ant - 如何在ant中访问属性内的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10703148/

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