Ant Macrodef属性用法

时间:2014-04-23 06:56:47

标签: ant scp

我在ant脚本中定义了一个宏,它将host作为参数:

<macrodef name="upload">
    <attribute name="host"/>
    <sequential>
    <echo>Uploading source code to @{host}...</echo>
    <scp trust="true" 
       file="package/code.zip"
       todir="${webserver.username}@@{host}:${webserver.upload_dir}" 
       keyfile="${webserver.keyfile}"
       passphrase="" />
    </sequential>
</macrodef>

问题是我无法弄清楚如何在todir字符串中使用@ {host},因为它已经有了&#39; @&#39;用户名和主机之间的字符。

1 个答案:

答案 0 :(得分:3)

Per:https://ant.apache.org/manual/Tasks/macrodef.html

The escape sequence @@ is used to escape @. 
This allows @{x} to be placed in the text without substitution of x by using @@{x}.

请尝试添加额外的&#39; @&#39;在获取主机属性值之前。

此外,您可以尝试设置<property name="token" value="@"/>并使用带有$ {token}的todir来查看是否有帮助

相关问题