Avoiding Escape: Characters in Ant Property Problem

I have thousands of properties in a property file, and I want to change only one property, for example the following.

<propertyfile file="${mypropetyfile}"> <entry key="jndiname" value="java:comp/env/wm/default"/> </propertyfile> 

but in the properties file I get the value of the property with an extra \ :

 jndiname=java\:comp/env/wm/default 

I tried to execute the <echo> task, but it removes other properties. I also tried concatenation, as in this case, and get extra \

 <propertyfile file="${mypropetyfile}"> <entry key="jndiname" default="" operation="+" value="java:comp/env/wm/default"/> </propertyfile> 
+6
ant
source share
4 answers

\ before : is an escape character. Although this is not necessary here because : it is not part of the key, but it is part of the value, this will not hurt either. Using the .load () property to load this property file will result in the disappearance of : You do not have to worry about running away.

+5
source share

Just ran into the same problem that changed the properties file read by Websphere 6.1 and he had to make 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}" /> 
+4
source share

The "best answer" does not really solve the problem. The Properties.load () function is not the answer, as in the case (which is very likely), you will not control the "other side" that will consume the properties file.

It seems you cannot set <propertyfile/> to not do this. This seems to be a mistake.

The <replace> clause seems like the best imo course of action.

+3
source share

I found that when I used the echo task, the record came out as expected / desired in the file.

However, if I subsequently ran the file properties task to fill the same file with some values, it escaped all the colons in the file.

To get around this, I just guaranteed that I ran the propertyfile task first, then the echo.

+1
source share

All Articles