How do I use properties in ants replace task?

2019-05-20 22:15发布

问题:

I need to replace a token with a property. That property has a path location set. I am not getting it as it is just replacing it with the $

<replace file="${APACHE_HOME}/conf/wc_server1.conf" >
  <replacetoken>@Install_Base_Directory@</replacetoken> 
<replacevalue>$InstallerBase</replacevalue>

回答1:

You basically have two options:

<replace file="${APACHE_HOME}/conf/wc_server1.conf" >
  <replacetoken><![CDATA[@Install_Base_Directory@]]></replacetoken> 
  <replacevalue><![CDATA[$InstallerBase]]></replacevalue>
</replace>

or since it's only a single line replace, use:

<replace file="${APACHE_HOME}/conf/wc_server1.conf" 
  token="@Install_Base_Directory@"
  value="$InstallerBase" />


回答2:

When using Ant properties you must enclose the property name in curlies {...} to get at the value:

<replacevalue>${InstallerBase}</replacevalue>


标签: ant replace