Ant:使用属性文件中的值替换文件中的所有标记

时间:2016-03-13 05:55:14

标签: ant

我正在编写一个ant脚本,它通过从另一个文件中获取其值来替换文件中的所有标记。 例如,文件a.properties包含标记,

server.url=@SERVER.URL@
application.id=@APP.ID@
etc...

标记的值应该从单个文件中获取,例如token.properties,其中包含以下条目

SERVER.URL=http://localhost:80
APP.ID=HelloWorld

我想在不提及每个令牌的替换过滤器的情况下完成此操作。我试过在网上搜索这个并且无法弄清楚。这可能在蚂蚁吗?

1 个答案:

答案 0 :(得分:1)

这是一个基于values.properties替换server.properties中的值的示例。

的build.xml

<?xml version="1.0"?>
<project name="Token Replacement" default="default">

   <target name="default">
      <replace file="server.properties" replacefilterfile="values.properties"/>
   </target>

</project>

server.properties - 需要绑定的文件

user.firstName=$firstName 
user.lastName=$lastName
user.company=$company

values.properties - 此文件中的属性将用于替换

$firstName=John
$lastName=Doe
$company=Acme
相关问题