大家好,请看一下这段代码
在我的属性文件中,我有 win-x86.pc-shared-location=E:\Ant_Scripts
Now below i am trying to call PrintInstallerName_build from my build.xml,while as PrintInstallerName_build is in test.xml. In build.xml file,${platform.id} has value=win-x86 in the calling target and in called target param1 also has 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>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,只有最后一条语句给出了正确的输出,但它是硬编码的,我想使用 param1 并且输出应该是E:\\Ant_Scripts我尝试使用 $ 和 @ 但没有任何效果,可能是我在某处做错了有人可以帮忙吗,我我很震惊,明天就是它的国防部。
请参阅Ant 手册的属性页面中的大括号嵌套。
在其默认配置中,Ant 不会尝试平衡属性扩展中的大括号,它只会在创建属性名称时使用直到第一个右大括号的文本。即当扩展像 ${a${b}} 这样的东西时,它会被翻译成两部分:
Run Code Online (Sandbox Code Playgroud)the expansion of property a${b - likely nothing useful. the literal text } resulting from the second closing brace这意味着您不能轻松地使用由属性指定名称的扩展属性,但是对于旧版本的 Ant,有一些变通方法。使用 Ant 1.8.0 和道具 Antlib,如果您需要这样的功能,您可以将 Ant 配置为使用那里定义的 NestedPropertyExpander。