Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问ant中属性内的属性_Ant - Fatal编程技术网

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

如何访问ant中属性内的属性,ant,Ant,大家好,请看一下这个代码 在我的属性文件中,我有 win-x86.pc共享位置=E:\Ant\u脚本 下面我尝试从build.xml调用PrintInstallerName\u build,而asPrintInstallerName\u build在test.xml中。在build.xml文件中,${platform.id}在调用的目标中有value=win-x86,在被调用的目标中,param1也有value=win-x86 <target name="PrintInstalle

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

在我的属性文件中,我有 win-x86.pc共享位置=E:\Ant\u脚本

下面我尝试从build.xml调用
PrintInstallerName\u build
,而as
PrintInstallerName\u build
在test.xml中。在build.xml文件中,
${platform.id}在调用的目标中有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>

PlatForm.Id==>${PlatForm.Id}
${param1.pc共享位置}
${param1}.pc共享位置}
${win-x86.pc共享位置}
正如您所看到的,只有最后一条语句给出了正确的输出,但它是硬编码的,我想使用param1,输出应该是
E:\\Ant\u Scripts
我尝试使用$and@但没有起作用,可能是我在某个地方做错了,有人能帮忙吗,我很震惊,明天是它的国防部。

请参阅Ant手册页面中的括号嵌套

在其默认配置中,Ant不会尝试在 属性扩展时,它将只使用第一个 创建属性名称时关闭大括号。即在扩展时 类似${a${b}的内容将被翻译成两部分:

the expansion of property a${b - likely nothing useful.
the literal text } resulting from the second closing brace
这意味着您无法使用名称为的轻松展开属性 由属性给定,但对于较旧的版本有一些变通方法 蚂蚁。使用Ant1.8.0和props Antlib,您可以配置Ant 如果需要这样一个函数,可以使用在此处定义的NestedPropertyExpander 特色


${param1}
${param1}的源目录:${@{v}
这就是它的工作方式,对我来说,不管怎样,它都很好。
@sudocode
你的提示带我去了那里,非常感谢你。你可以使用
来实现它。
考虑您需要具有<代码> {$PRO$${PROB}} < /代码>

的属性值。 使用
propertycopy
的ant标记,如下所示:

<propertycopy property="myproperty" from="PropA.${PropB}"/>

<echo >${myproperty}</echo>

${myproperty}
这将回显
${propA${propB}}

的值。这可能是一条金线的重复项
<propertycopy property="myproperty" from="PropA.${PropB}"/>

<echo >${myproperty}</echo>