我如何更改使用Ant文件的属性值? [英] How can I change property values in a file using Ant?
本文介绍了我如何更改使用Ant文件的属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
输入示例:
SERVER_NAME=server1
PROFILE_NAME=profile1
...
输出示例:
SERVER_NAME=server3
PROFILE_NAME=profile3
...
这个文件将在的applicationContext.xml
使用。我试过
This file will use in applicationContext.xml
. I've tried
<copy file="${web.dir}/jexamples.css_tpl"
tofile="${web.dir}/jexamples.css" >
<filterchain>
<replacetokens>
<token key="SERVER_NAME" value="server2"/>
<token key="PROFILE_NAME" value="profi"/>
</replacetokens>
</filterchain>
</copy>
,但它不工作
推荐答案
您 filterchain
是好的,但你的源文件应该是这样的:
Your filterchain
is ok, but your source file should look like this:
SERVER_NAME=@SERVER_NAME@
PROFILE_NAME=@PROFILE_NAME@
这code(由您提供)
This code (as provided by you)
<copy file="${web.dir}/jexamples.css_tpl"
tofile="${web.dir}/jexamples.css" >
<filterchain>
<replacetokens>
<token key="SERVER_NAME" value="server2"/>
<token key="PROFILE_NAME" value="profi"/>
</replacetokens>
</filterchain>
</copy>
替换标记,让您
SERVER_NAME=server2
PROFILE_NAME=profi
如果你想保持你有现在你的原始文件,一种办法是使用<一个href=\"http://ant.apache.org/manual/Types/filterchain.html#replaceregex\"><$c$c>replaceregex$c$c>:
<filterchain>
<tokenfilter>
<replaceregex pattern="^[ \t]*SERVER_NAME[ \t]*=.*$"
replace="SERVER_NAME=server2"/>
<replaceregex pattern="^[ \t]*PROFILE_NAME[ \t]*=.*$"
replace="PROFILE_NAME=profi"/>
</tokenfilter>
</filterchain>
这将取代每行开头 SERVER_NAME =
按 SERVER_NAME =服务器2
(同为 PROFILE_NAME =
)。这将返回得到你所描述的输出。
This would replace every line starting with SERVER_NAME=
by SERVER_NAME=server2
(same for PROFILE_NAME=
). This will return get you the output you described.
[\\ t] *
是忽略空白。
这篇关于我如何更改使用Ant文件的属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文