med_alpa
med_alpa

Reputation: 292

Ant script : Replace only the value of the key in a java property file

I'm using this script to replace a value in a property file located into a jar file.

<replace file="/cygdrive/d/ant/test/target/com/test/resources.properties" token="MyKey" value="MyNewValue">

the property file is :

MyKey=My Old Value

This script will replace MyKey by MyNewValue Or what I need is to replace the My Old Value by the MyNewValue?

Upvotes: 3

Views: 2617

Answers (2)

martin clayton
martin clayton

Reputation: 78105

You might use the Ant propertyfile task, something like:

<propertyfile file="/cygdrive/d/ant/test/target/com/test/resources.properties">
    <entry key="MyKey" value="MyNewValue"/>
</propertyfile>

Upvotes: 3

Steve Bazyl
Steve Bazyl

Reputation: 11672

The replace task is simple string replacement, and it did exactly what you asked it to do -- replaced the occurrence of the string "MyKey" with the string "MyNewValue" in the properties file (it doesn't know it's a property file, just treats it as text.) If you want it to replace "My Old Value" then that's what you'd specify in the token parameter.

If you're just looking to have placeholder values in a properties file that you set at build/deploy time, then you might want to look at the filter task if you have lots of properties to deal with.

Upvotes: 0

Related Questions