Problem displaying file path properties in ant

I am having trouble writing a property that contains the value of the directory path in the properties file.

My script initially reads in this particular property, calls it "appserver.home" from the props with <property file="source.props"/>. I repeated the value included in it and it reads correctly, like C: \\ somedir \\ jboss_4_2_3.

What my next script should execute is the value for another properties file (used by another ant script - although this is not important). To create this other file, I use a kind template file with place owners surrounded by $ .... $ to insert the correct values ​​in the right 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 now the value in target.props is C: \ somedir \ jboss_4_2_3, i.e. it has lost escape characters. When the following ant script uses this file, it interprets the property value as C: somedirjboss_4_2_3.

So the question is, how can I tell ant that the value I am writing is a file path? Note. I tried the following, which actually works: -

<propertyfile file="target.props">
    <entry key="appServerDir" value="${appserver.home}"/>
</propertyfile>

.. i.e. displays the name as c \: \\ somedir \\ jboss4_2_3, but I would rather not use this method and, rather, use the template file technique, since it contains some properties that are always static, as well as comments, etc.

Thanks in advance

+3
source share
4 answers

, .

, "appserver.home" , , "echoproperties", , . , source.props.

, , Ant , escape-, . " ", , escape- - , - .

, ?

, - , , 'source.props', .

<property file="source.props"/>

,

<loadproperties srcfile="source.props">
    <filterchain>
        <replacestring from="\" to="\\" />
    </filterchain>
</loadproperties>

, escape- .

+3

, Apache Ant version 1.7.1 compiled on May 25 2010 Ubuntu 10.10, Apache Ant 1.7.1, 27 2008 Eclipse 3.6 Windows XP. ( ):

source.props:
appserver.home=C\:\\somedir\\jboss_4_2_3

:
[echo] C:\somedir\jboss_4_2_3

target.properties:
appserver.home=C:\somedir\jboss_4_2_3

EDIT - ; -D

-, propertyfile, , , MANIPUlate . , .

<copy file="template_file.props"  tofile="target.props" />
<propertyfile  file="target.props">
    <entry  key="appserver.home" value="${appserver.home}"/>
</propertyfile>
+1

I just tested the following using integrated ant Eclipse support:

<copy file="test.props" tofile="target.props">
    <filterset begintoken="$" endtoken="$">
    <filter token="appServerDir" value="C\:\\somedir\\jboss_4_2_3"/>
    </filterset>
</copy> 

and it generates the following file:

C\:\\\somedir\\\jboss_4_2_3

What version of ant are you using?

0
source

As a workaround, you can also write your initial property using forward slashes, as C:/somedir/jboss_4_2_3for which no escape characters are required.

0
source

Source: https://habr.com/ru/post/1757098/


All Articles