问题 带有@符号的变量在Ant build.xml中的含义是什么?


谁能告诉我在ant build.xml文件中变量之前的@符号是什么意思?

<subant target="@{target}">

非常感谢!


8175
2018-03-09 14:57


起源

这意味着您处于宏定义中。 - bmargulies


答案:


(core)ant中没有变量,但是属性和属性。
@ {foo}是访问macrodef中macrodef属性值的语法,即:

<project name="tryme">
 <macrodef name="whatever">
  <attribute name="foo" default="bar"/>
   <sequential>
    <echo>foo =>  @{foo}</echo>
   </sequential>
 </macrodef>

 <!-- testing 1, foo attribute not set, will use default value -->
 <whatever/>

 <!-- testing 2,  set attribute foo to 'baz'-->
 <whatever foo="baz"/>
</project>

输出:

 [echo] foo =>  bar
 [echo] foo =>  baz

看到 蚂蚁手动macrodef
而$ {foo}是访问属性值的语法:

<project name="demo">
 <property name="foo" value="bar"/>
 <echo>$${foo} => ${foo}</echo>
</project>

输出:

[echo] ${foo} => bar

看到 蚂蚁手工财产


15
2018-03-09 21:11



你打败了我! :-) - Mark O'Connor
罢工;-)干杯|| Slàintemhath - Rebse