I have thousands of properties in my property file and I want to change only one property like the following.
<propertyfile file="${mypropetyfile}">
<entry key="jndiname" value="java:comp/env/wm/default"/>
</propertyfile>
but in the property file I am getting the property value with an extra \
:
jndiname=java\:comp/env/wm/default
I tried with the <echo>
task but it removes other properties. I also tried by concatenation like following in this case also I am getting extra \
<propertyfile file="${mypropetyfile}">
<entry key="jndiname" default="" operation="+" value="java:comp/env/wm/default"/>
</propertyfile>
The \
before the :
is an escape character. Although it's not necessary here because the :
is not part of the key, but is part of the value, it doesn't hurt either. Using Properties.load() to load this properties file will unescape the :
. You should not care about the escape.
Just ran into the same problem changing a property file read by Websphere 6.1 & ended up having to do this workaround:
<property name="jndi.example" value="java:comp/env/example" />
<propertyfile file="jdbc.properties">
<entry key="datasource.example.jndi" operation="=" value="@EXAMPLE"/>
</propertyfile>
<!-- set tokens to property values because ant wants to 'escape the colon' -->
<replace file="jdbc.properties" token="@EXAMPLE" value="${jndi.example}" />
The 'best answer' isn't really addressing the problem. The Properties.load() is not the answer as in the case (which is highly likely), you won't control the 'other side' that will be consuming the properties file.
It doesn't appear you can set the <propertyfile/>
to not do this. Seems like a bug to me.
The <replace>
suggestion seems like the best course of action imo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With