使用Ant脚本将令牌从一个文件替换为另一个文件 [英] Replace tokens from one file to another using Ant script

查看:352
本文介绍了使用Ant脚本将令牌从一个文件替换为另一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下ant的filterchain和replacetoken将一个资源包(.messages文件)中的几个令牌替换为另一个资源.

I am trying to replace few tokens from one resource bundle (.messages file) to another one using the below ant's filterchain and replacetoken.

<copy file="dev.properties" tofile="messages.properties">
    <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>

目标运行正常,但没有任何复制.这是我的文件.

The target runs fine but nothing gets copied. Here are my files.

dev.properties

dev.properties

server.name=myServerName
server.ip=127.0.0.1

messages.properties

messages.properties

SERVER_NAME="@server.name@"
SERVER_IP="@server.ip@"

请注意,messages.properties是部署到服务器的内容.它具有所有环境通用的其他条目.我正在使用Jenkins将项目部署到差异环境中.我的计划是在部署后将其称为ANT目标/任务,在messages.properties中将环境/服务器特定的变量替换为端口,名称等,然后使用Jenkins进行构建到应用服务器.

Please note that messages.properties is what gets deployed to the server. It has other entries which are common to all the environments. I am using Jenkins to deploy the projects to diff environments. My plan is call this ANT target/task as a post deployment step, replace the environment/server specific variables as port, name etc in messages.properties and then do the build to app server using Jenkins.

推荐答案

您可以尝试以下方法:

You can try this:

<project name="MyProject" default="useregex" basedir=".">
    <target name="useregex">
        <property file="dev.properties"/>
        <replace  file="messages.properties" token="@server.name@" value="${server.name}" />
        <replace  file="messages.properties" token="@server.ip@" value="${server.ip}" />
    </target>
</project>

这篇关于使用Ant脚本将令牌从一个文件替换为另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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