覆盖属性文件中的一个值 [英] Override one value in properties file
问题描述
我有一个性能文件:
custom.properties 的
custom.properties
该属性文件的内容是:
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变化-ID,属性文件的内容就变成了:
I run ant change-id , the content of the properties file becomes:
aaa=sf2j2345kkklljhlaasfsdfafsf543
name=SOME_NAME
这是关键 ID
被替换,而不是它的值。但是,我需要更换价值的 AAA ,如何在蚂蚁实现这一目标?
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?
请不要推荐我设置标记
到标识的
随机值因为这个值是随机生成的,放在那里。我只是想通过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
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>
我完全不知道这是否定期EX pression是正确的,但,这是你可以做到这一点。
I don't know exactly if this regular expression is correct but this is the way you can do it.
这篇关于覆盖属性文件中的一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!