覆盖属性文件中的一个值 [英] Override one value in properties file

查看:27
本文介绍了覆盖属性文件中的一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个属性文件:

custom.properties

这个属性文件的内容是:

the content of this properties file is:

id=sf2j2345kkklljhlaasfsdfafsf543
name=SOME_NAME

id 的值是一个长随机字符串.

The value of id is a long random string.

我想制作一个 Ant 脚本来替换/覆盖 id 的值到另一个,我用 Ant 语法:

I want to make an Ant script to replace/over-write the value of id to another one, I tried with Ant <replace> syntax:

<target name="change-id">
      <replace file="custom.properties" token="id" value="aaa" />
</target>

我运行 ant change-id ,属性文件的内容变为:

I run ant change-id , the content of the properties file becomes:

aaa=sf2j2345kkklljhlaasfsdfafsf543
name=SOME_NAME

那是键id"被替换而不是它的值.但是我需要将值替换为 "aaa" ,如何在 Ant 中实现这一点?

That's the key "id" get replaced instead of its value. But I need to replace the value to "aaa" , how to achieve this in Ant?

请不要建议我token 设置为 id 的随机值,因为该值是随机生成并放在那里的.我只想通过Ant脚本覆盖id"的随机值,如何实现?.

Please do not recommend me to set token to id's random value, because that value is random generated and put there. I only want to over-write the random value of "id" by Ant script, how to achieve this?.

推荐答案

您可以使用 replaceregexp 任务来完成.尝试像在这个例子中那样做

You can do it using replaceregexp task. Try to do it like in this example

conf.ini (utf-8)

conf.ini (utf-8)

aaa=sf2j2345kkklljhlaasfsdfafsf543
name=SOME_NAME

build.xml

<project name="regexp.replace.test" default="test">

    <target name="test">
        <replaceregexp file="conf.ini" match="^aaa=.*" replace="aaa=newId" encoding="UTF-8" />
    </target>

</project>

我不知道这个正则表达式是否正确,但这是你可以做到的.

I don't know exactly if this regular expression is correct but this is the way you can do it.

这篇关于覆盖属性文件中的一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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