I’m having an issue with writing out a property which holds the value of a directory path into a property file.
My script originally reads in this particular property, call it ‘appserver.home’, from a props file using the <property file="source.props"/>. I’ve echoed the value coming in and it reads correctly as C:\\somedir\\jboss_4_2_3.
What my script needs to do next is provide this value to another properties file (used by another ant script – though that’s not important). To create this other file I’m using a kind off template file with place holders surrounded by $….$ to insert the correct values in the correct place, using the following :-
<copy file="template_file.props" tofile="target.props">
<filterset begintoken="$" endtoken="$">
<filter token="appServerDir" value="${appserver.home}"/>
<filter token="dbusername" value="${database.name}"/>
....
</filterset>
</copy>
The problem is that the value now in the target.props is C:\somedir\jboss_4_2_3 ie it’s lost the escape characters. When the next ant script uses this file it interprets the property value as C:somedirjboss_4_2_3.
So the question how do I tell ant that the value I’m writing is a file path ?
Note I have tried the following, which actually works :-
<propertyfile file="target.props">
<entry key="appServerDir" value="${appserver.home}"/>
</propertyfile>
.. ie it outputs the name as c\:\\somedir\\jboss4_2_3, but I’d rather not use this technique and rather use the template file technique, as it contains some properties which are always static, as well as comments etc.
Thanks in advance
There’s some perhaps confusing differences between tasks in respect of the treatment of escapes going on here.
When you say that ‘appserver.home’ echoes correctly, I guess you are using the ‘echoproperties’ task which shows you the value stored without interpolating escapes. And that shows the same number of escapes as in your ‘source.props’ file.
The problem is that, in general, when Ant interpolates this value in to a string it will consume the escapes, hence they disappear. An exception to this is in the ‘propertyfile’ task, where you would normally want the escapes retained in the output property file – as you have observed – in order that the file can be read properly later.
So, what to do?
Perhaps the simplest thing is to make sure that the properties read from ‘source.props’ retain their escapes for use in later filters. So instead of using
to load, use
That should ensure that your escape sequences propagate.