【问题标题】:Ant: Replace all tokens in a file, with its values from a property fileAnt:用属性文件中的值替换文件中的所有标记
【发布时间】:2016-03-13 05:55:13
【问题描述】:

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

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

令牌的值应该从单个文件中获取,比如包含以下条目的 token.properties

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

我想在不提及每个标记的替换过滤器的情况下完成此操作。我曾尝试在网上搜索此内容,但无法弄清楚。这在蚂蚁中可能吗?

【问题讨论】:

标签: ant


【解决方案1】:

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

构建.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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多