Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not Escape : Characters in Ant propertyfile task

Tags:

ant

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> 
like image 501
Vinayaka Kulkarni Avatar asked Feb 23 '11 09:02

Vinayaka Kulkarni


3 Answers

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.

like image 109
JB Nizet Avatar answered Oct 16 '22 17:10

JB Nizet


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}" />
like image 42
blank Avatar answered Oct 16 '22 17:10

blank


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.

like image 3
Scott W. Avatar answered Oct 16 '22 19:10

Scott W.