使用 ANT 替换基于属性文件的所有令牌
我很确定这是一个简单的问题,而且我之前也见过这个问题,但没有可靠的答案。
我有几个用于不同环境的属性文件,即 xxxx-dev、xxxx-test、xxxx-live
属性文件包含类似以下内容:
server.name=dummy_server_name
server.ip=127.0.0.1
我使用的模板文件看起来像:
<...>
<server name="@server.name@" ip="@server.ip@"/>
</...>
上面是一个非常原始的示例,但我想知道是否有一种方法可以告诉 ANT 根据属性文件替换所有令牌,而不是必须为每个令牌行硬编码...即
<replacetokens>
<token key="server.name" value="${server.name}"/>
<token key="server.ip" value="${server.ip}"/>
</replacetokens>
任何帮助都会很棒!
I'm pretty sure this is a simple question to answer and ive seen it asked before just no solid answers.
I have several properties files that are used for different environments, i.e xxxx-dev, xxxx-test, xxxx-live
The properties files contain something like:
server.name=dummy_server_name
server.ip=127.0.0.1
The template files im using look something like:
<...>
<server name="@server.name@" ip="@server.ip@"/>
</...>
The above is a really primitive example, but im wondering if there is a way to just tell ANT to replace all tokens based on the properties file, rather than having to hardcode a token line for each... i.e
<replacetokens>
<token key="server.name" value="${server.name}"/>
<token key="server.ip" value="${server.ip}"/>
</replacetokens>
Any help would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以指定属性文件,从中读取 'replace' 任务< /a> using
replacefilterfile
:同样,在过滤器链中,您可以使用 “替换令牌”
propertyfile
:You can specify the properties file from which to read the list of tokens for the 'replace' task using
replacefilterfile
:Similarly, in a filter chain, you can use 'replacetokens'
propertyfile
:通过替换任务本身,我错过了标记周围的 @ 分隔符,因此我提出了以下解决方案。您可以将模板文件中的任何 ant 属性
与模板
一起使用,这会导致
With the replace task by itself I missed the @ delimiters around tokens so I came up with the following solution. You can use any ant property in the template file
with a template
this results in
使用文件集表单
ant-contrib
您可以读取令牌表单属性文件并替换多个文件中的多个令牌。文件夹结构:
为了替换单个令牌,请使用以下内容:
Using fileset form
ant-contrib
you can read the tokens form properties file and replace multiple tokens over multiple files.folder structure:
In order to replace single toke use the following: