You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by David Hoffer <dh...@gmail.com> on 2015/01/28 20:16:54 UTC

How to escape variable interpolation?

I have a case where I have a text file that is generated with a hard coded
string and I would like to replace that with Maven variables, but I want
the literal variable string to go in the file not the interpolated values.

I read http://maven.apache.org/shared/maven-filtering/ that i should be
able to do this with a leading \ but that doesn't work.  It still
resolves ${service.root.url}.

<execution>
    <id>replace-namespace</id>
    <phase>generate-resources</phase>
    <goals>
        <goal>run</goal>
    </goals>
    <configuration>
        <failOnError>true</failOnError>
        <target>
            <replace
dir="${project.build.directory}/generated-resources/META-INF/" token="
http://jmsappsvr/bullpen/service"
value="\${service.root.url}/bullpen/readwrite" >
                <include name="**/*.wsdl" />
            </replace>
        </target>
    </configuration>
</execution>

How can this be done?

-Dave

Re: How to escape variable interpolation?

Posted by David Hoffer <dh...@gmail.com>.
Thanks for all the suggestions.  I tried them all but no luck.

\\\${service.root.url}/bullpen/readwrite does not stop variable replacement.
 ${dollar}{service.root.url} does not stop it either it actually resolves
the nested variables.
\u0024{service.root.url}/bullpen/readwrite does stop variable replacement
but then when you want to do the replacement it doesn't work.

It sure would be good if Maven used this
http://maven.apache.org/shared/maven-filtering/ approach everywhere.  Is
there a place I can make that request?

-Dave

On Thu, Jan 29, 2015 at 2:14 AM, Thomas Broyer <t....@gmail.com> wrote:

> On Wed Jan 28 2015 at 20:18:53 David Hoffer <dh...@gmail.com> wrote:
>
> > I have a case where I have a text file that is generated with a hard
> coded
> > string and I would like to replace that with Maven variables, but I want
> > the literal variable string to go in the file not the interpolated
> values.
> >
> > I read http://maven.apache.org/shared/maven-filtering/ that i should be
> > able to do this with a leading \ but that doesn't work.  It still
> > resolves ${service.root.url}.
> >
> > <execution>
> >     <id>replace-namespace</id>
> >     <phase>generate-resources</phase>
> >     <goals>
> >         <goal>run</goal>
> >     </goals>
> >     <configuration>
> >         <failOnError>true</failOnError>
> >         <target>
> >             <replace
> > dir="${project.build.directory}/generated-resources/META-INF/" token="
> > http://jmsappsvr/bullpen/service"
> > value="\${service.root.url}/bullpen/readwrite" >
> >
>
> That property is substituted during evaluation of the POM, not by the
> maven-filtering (which, to my knowledge, is not used in this case).
>
> According to https://stackoverflow.com/q/7751696/116472,
> $${service.root.url} might work (or not). Using a unicode escape for the
> '$' sign worked for some people:
> value="\u0024{service.root.url}/bullpen/readwrite"; and despite the
> comments in this QA, I'd try defining a <dollar>$</dollar> property and
> then using ${dollar}{service.root.url}.
>

Re: How to escape variable interpolation?

Posted by Thomas Broyer <t....@gmail.com>.
On Wed Jan 28 2015 at 20:18:53 David Hoffer <dh...@gmail.com> wrote:

> I have a case where I have a text file that is generated with a hard coded
> string and I would like to replace that with Maven variables, but I want
> the literal variable string to go in the file not the interpolated values.
>
> I read http://maven.apache.org/shared/maven-filtering/ that i should be
> able to do this with a leading \ but that doesn't work.  It still
> resolves ${service.root.url}.
>
> <execution>
>     <id>replace-namespace</id>
>     <phase>generate-resources</phase>
>     <goals>
>         <goal>run</goal>
>     </goals>
>     <configuration>
>         <failOnError>true</failOnError>
>         <target>
>             <replace
> dir="${project.build.directory}/generated-resources/META-INF/" token="
> http://jmsappsvr/bullpen/service"
> value="\${service.root.url}/bullpen/readwrite" >
>

That property is substituted during evaluation of the POM, not by the
maven-filtering (which, to my knowledge, is not used in this case).

According to https://stackoverflow.com/q/7751696/116472,
$${service.root.url} might work (or not). Using a unicode escape for the
'$' sign worked for some people:
value="\u0024{service.root.url}/bullpen/readwrite"; and despite the
comments in this QA, I'd try defining a <dollar>$</dollar> property and
then using ${dollar}{service.root.url}.

Re: How to escape variable interpolation?

Posted by Jörg Schaible <jo...@swisspost.com>.
David Hoffer wrote:

> I have a case where I have a text file that is generated with a hard coded
> string and I would like to replace that with Maven variables, but I want
> the literal variable string to go in the file not the interpolated values.
> 
> I read http://maven.apache.org/shared/maven-filtering/ that i should be
> able to do this with a leading \ but that doesn't work.  It still
> resolves ${service.root.url}.
> 
> <execution>
>     <id>replace-namespace</id>
>     <phase>generate-resources</phase>
>     <goals>
>         <goal>run</goal>
>     </goals>
>     <configuration>
>         <failOnError>true</failOnError>
>         <target>
>             <replace
> dir="${project.build.directory}/generated-resources/META-INF/" token="
> http://jmsappsvr/bullpen/service"
> value="\${service.root.url}/bullpen/readwrite" >
>                 <include name="**/*.wsdl" />
>             </replace>
>         </target>
>     </configuration>
> </execution>
> 
> How can this be done?
> 
> -Dave


Try:

  value="\\\${service.root.url}/bullpen/readwrite"

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org