有人能告诉我在ant build.xml文件中变量之前的@符号是什么意思吗?
<subant target="@{target}">
非常感谢!
答案 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