ANT 使用具有属性的文件替换指定文件中的字符串 [英] ANT replacing strings in specified files using file with properties

查看:26
本文介绍了ANT 使用具有属性的文件替换指定文件中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件 dev.properties 中有一个属性,它们看起来像这样:

I have a properties in file dev.properties and they look like this:

test.url=https://www.example.com/
[...]

并且在项目文件中有一个令牌 [[test.url]],我想用 https://替换它www.example.com/.我只想在 dev.properties 中定义所有令牌并在构建脚本中使用它们,但不修改构建脚本,我想在指定的文件(如 *.php、*.html 等)中替换这些令牌.

and in project files there is a token [[test.url]] which I want to replace by https://www.example.com/. I just want to define all tokens in dev.properties and use them in build script, but without modifying build script and I want to replace those tokens in a specified files like *.php, *.html, etc.

有人可以给我建议怎么做吗?谢谢.

Can someone give me a suggestions how to do it? Thanks.

推荐答案

试试这个:

<copy file="input.txt" tofile="output.txt">
   <filterchain>
   <replaceregex pattern="\$\{" replace="{" />
   <filterreader classname="org.apache.tools.ant.filters.ReplaceTokens">
        <param type="propertiesfile" value="properties.txt"/>
        <param type="tokenchar" name="begintoken" value="{"/>
        <param type="tokenchar" name="endtoken" value="}"/>
    </filterreader>
    </filterchain>
</copy>

在这里创建:Ant 替换属性文件中的令牌

这篇关于ANT 使用具有属性的文件替换指定文件中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆