0

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

server.name=myServerName server.ip=127.0.0.1 

messages.properties

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

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.

2
  • What are you using ant instead of the filtering of Maven ? Commented Sep 18, 2014 at 8:19
  • The project was started as a Maven project and has Maven structure. Due to company security blocking downloads from few sites the Maven nature has been disabled for now. The project is built in JDeveloper 12c. We deploy it through Jenkin which uses JDeveloper project related files (.jws etc..) to build the projects. Does Jenkins need any plugins for replacing tokens? As a pre deployment step, can I create/use a Maven goal only to replace tokens? Commented Sep 18, 2014 at 14:03

2 Answers 2

1

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> 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Technext. I got that from another thread; I was hoping to avoid adding "replace" for every token.
Good to hear this! :) Can you please post your solution as an answer so that others can benefit from the same?
0

This is what worked for me. I was hoping for a better answer from somebody on filterchain.

 <target name="replaceLocalTokens"> <property file="local.properties"/> <replace file="messages.properties" token="@build-number@" value="${build.number}"/> <replace file="messages.properties" token="@build-date@" value="${build.date}"/> <replace file="messages.properties" token="@server-name@" value="${server.name}"/> <replace file="messages.properties" token="@ssl-port@" value="${ssl.port}"/> </target> 

2 Comments

Well, how is it different from what i suggested? :)
I think you misunderstood me. What I said was that I got the workaround you suggested from another thread and that somebody would provide a clean solution to it using filterchain. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.