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

时间:2012-03-09 14:57:39

标签: ant

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

<subant target="@{target}">

非常感谢!

1 个答案:

答案 0 :(得分:17)

(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

Ant manual macrodef
而$ {foo}是访问属性值的语法:

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

输出:

[echo] ${foo} => bar

请参阅Ant manual property