You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Phillip Hellewell <ss...@gmail.com> on 2011/04/21 19:39:24 UTC

Variables interpolated on the command-line

I'm having trouble running a plugin I wrote and setting a variable to
another variable that I want to interpolate later.

I've had success inside pom files by escaping the $ as $$, but from
the command-line that is not working.

What's weird is that it is inconsistent about when it will interpolate
it or not, e.g.:

mvn myplugin:mygoal -Dmyvar1=${myvar2}   => this sets myvar1 to
literally "${myvar2}", without interpolation

mvn myplugin:mygoal -Dmyvar1="c:\test\${myvar2}"  => this one
interpolates it so I get myvar1 set to "c:\test\null"

How can I make the second one work?

Phillip

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


Re: Variables interpolated on the command-line

Posted by Phillip Hellewell <ss...@gmail.com>.
On Fri, Apr 22, 2011 at 9:07 PM, Ron Wheeler
<rw...@artifact-software.com> wrote:
> You said :
>
> If I write mvn blah -Dprop1=${prop2} Maven sets prop1 to null.
>
> This is not correct.
> What you should have written is
> If I write mvn blah -Dprop1=${prop2} my operating system converts
> -Dprop1=${prop2} to -Dprop1=null
> before passing it to Maven, since it has no environment called prop2 so it
> converts it to "null".

WRONG!  I am on Windows, not Linux/Unix.  Windows command prompt does
NOT do anything to ${prop2}.

Maven is converting it to null.

Phillip

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


Re: Variables interpolated on the command-line

Posted by Ron Wheeler <rw...@artifact-software.com>.
I am not sure but I think that the previous comments about DOS or Unix 
were trying to point out that variables on the command line are 
transformed by the operating system PRIOR to Maven getting them so you 
need to find a way to get your operating system to read your command 
line and transform it into something that will get passed to Maven in a 
form that you want.

You said :

If I write mvn blah -Dprop1=${prop2} Maven sets prop1 to null.

This is not correct.
What you should have written is
If I write mvn blah -Dprop1=${prop2} my operating system converts -Dprop1=${prop2} to -Dprop1=null
before passing it to Maven, since it has no environment called prop2 so it converts it to "null".

Then you said:
If I write mvn blah -Dprop1=$${prop2} it sets prop1 to $null
What you should have said was:
If I write mvn blah -Dprop1=$${prop2} the OS convertss -Dprop1=$${prop2} to -Dprop1=$null
before passing it to Maven since it thinks prop2 is not defined (ie null).

You fight is with your OS not Maven.

You might want to test this with the echo command rather than mvn to see the actual arguments that will get sent to the program.

I hope that this helps.


Ron
  

On 22/04/2011 10:40 PM, Phillip Hellewell wrote:
> I appreciate the two responses, but no one seems to be grasping what
> I'm talking about.
>
> Erase from your mind anything about %dos_env_vars% or $unix_env_vars.
> My question has exactly 0 to do with env vars.
>
> My question is about maven properties.  In a pom file I can set a
> property to the value of another property by writing
> <prop1>${prop2}<prop1>, or if I want to set it to the literal value
> "${prop2}" I can write<prop1>$${prop2}<prop1>.  The extra $ escapes
> it and keeps it from getting interpolated.
>
> However, on the command-line, I cannot find any way to accomplish the
> same thing.  If I write mvn blah -Dprop1=${prop2} Maven sets prop1 to
> null.  If I write mvn blah -Dprop1=$${prop2} it sets prop1 to $null.
> The only way I have found to keep it from interpolating is by
> appending text.
>
> Is this by design or a bug?  I'd say it is a bug because if it's going
> to interpolate at all it ought to be consistent and should work the
> same way as when inside a pom file.
>
> Phillip
>
> On Thu, Apr 21, 2011 at 6:16 PM, Sony Antony<so...@gmail.com>  wrote:
>> I think %myvar2% will result in windows shell doing teh substitution
>> I dont think maven will use system variables set using -D as pom variables (
>> maybe I m wrong )
>> --sony
>> On Thu, Apr 21, 2011 at 7:24 PM, Phillip Hellewell<ss...@gmail.com>  wrote:
>>
>>> This is on Windows from a command prompt, not Linux.
>>>
>>> Phillip
>>>
>>> On Thu, Apr 21, 2011 at 12:21 PM, Jörg Schaible<jo...@gmx.de>
>>> wrote:
>>>> Phillip Hellewell wrote:
>>>>
>>>>> Oh, I just thought of something shorter that will work:
>>>>>
>>>>> -Dmyvar1=c:\test\${myvar2}\.
>>>>>
>>>>> Still seems kinda crazy though.  Anyone want to shed some light on why
>>>>> it works this way?  This is with Maven 3.0.1.
>>>> Maybe you should have a look into the bash manual instead ?
>>>>
>>>> - Jörg
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


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


Re: Variables interpolated on the command-line

Posted by Phillip Hellewell <ss...@gmail.com>.
On Fri, Apr 22, 2011 at 8:49 PM, Sony Antony <so...@gmail.com> wrote:
> what will happen if you put it under quotes '-Dprop1=${prop2}' ?

Thanks for the idea.  I tried that and I tried surrounding the whole
thing with double quotes.  With single quotes I got an error; with
double quotes it behaved the same as always.

Phillip

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


Re: Variables interpolated on the command-line

Posted by Sony Antony <so...@gmail.com>.
what will happen if you put it under quotes '-Dprop1=${prop2}' ?
--sony

On Fri, Apr 22, 2011 at 10:40 PM, Phillip Hellewell <ss...@gmail.com>wrote:

> I appreciate the two responses, but no one seems to be grasping what
> I'm talking about.
>
> Erase from your mind anything about %dos_env_vars% or $unix_env_vars.
> My question has exactly 0 to do with env vars.
>
> My question is about maven properties.  In a pom file I can set a
> property to the value of another property by writing
> <prop1>${prop2}<prop1>, or if I want to set it to the literal value
> "${prop2}" I can write <prop1>$${prop2}<prop1>.  The extra $ escapes
> it and keeps it from getting interpolated.
>
> However, on the command-line, I cannot find any way to accomplish the
> same thing.  If I write mvn blah -Dprop1=${prop2} Maven sets prop1 to
> null.  If I write mvn blah -Dprop1=$${prop2} it sets prop1 to $null.
> The only way I have found to keep it from interpolating is by
> appending text.
>
> Is this by design or a bug?  I'd say it is a bug because if it's going
> to interpolate at all it ought to be consistent and should work the
> same way as when inside a pom file.
>
> Phillip
>
> On Thu, Apr 21, 2011 at 6:16 PM, Sony Antony <so...@gmail.com>
> wrote:
> > I think %myvar2% will result in windows shell doing teh substitution
> > I dont think maven will use system variables set using -D as pom
> variables (
> > maybe I m wrong )
> > --sony
> > On Thu, Apr 21, 2011 at 7:24 PM, Phillip Hellewell <ss...@gmail.com>
> wrote:
> >
> >> This is on Windows from a command prompt, not Linux.
> >>
> >> Phillip
> >>
> >> On Thu, Apr 21, 2011 at 12:21 PM, Jörg Schaible <jo...@gmx.de>
> >> wrote:
> >> > Phillip Hellewell wrote:
> >> >
> >> >> Oh, I just thought of something shorter that will work:
> >> >>
> >> >> -Dmyvar1=c:\test\${myvar2}\.
> >> >>
> >> >> Still seems kinda crazy though.  Anyone want to shed some light on
> why
> >> >> it works this way?  This is with Maven 3.0.1.
> >> >
> >> > Maybe you should have a look into the bash manual instead ?
> >> >
> >> > - Jörg
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >> > For additional commands, e-mail: users-help@maven.apache.org
> >> >
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: users-help@maven.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Variables interpolated on the command-line

Posted by Phillip Hellewell <ss...@gmail.com>.
I appreciate the two responses, but no one seems to be grasping what
I'm talking about.

Erase from your mind anything about %dos_env_vars% or $unix_env_vars.
My question has exactly 0 to do with env vars.

My question is about maven properties.  In a pom file I can set a
property to the value of another property by writing
<prop1>${prop2}<prop1>, or if I want to set it to the literal value
"${prop2}" I can write <prop1>$${prop2}<prop1>.  The extra $ escapes
it and keeps it from getting interpolated.

However, on the command-line, I cannot find any way to accomplish the
same thing.  If I write mvn blah -Dprop1=${prop2} Maven sets prop1 to
null.  If I write mvn blah -Dprop1=$${prop2} it sets prop1 to $null.
The only way I have found to keep it from interpolating is by
appending text.

Is this by design or a bug?  I'd say it is a bug because if it's going
to interpolate at all it ought to be consistent and should work the
same way as when inside a pom file.

Phillip

On Thu, Apr 21, 2011 at 6:16 PM, Sony Antony <so...@gmail.com> wrote:
> I think %myvar2% will result in windows shell doing teh substitution
> I dont think maven will use system variables set using -D as pom variables (
> maybe I m wrong )
> --sony
> On Thu, Apr 21, 2011 at 7:24 PM, Phillip Hellewell <ss...@gmail.com> wrote:
>
>> This is on Windows from a command prompt, not Linux.
>>
>> Phillip
>>
>> On Thu, Apr 21, 2011 at 12:21 PM, Jörg Schaible <jo...@gmx.de>
>> wrote:
>> > Phillip Hellewell wrote:
>> >
>> >> Oh, I just thought of something shorter that will work:
>> >>
>> >> -Dmyvar1=c:\test\${myvar2}\.
>> >>
>> >> Still seems kinda crazy though.  Anyone want to shed some light on why
>> >> it works this way?  This is with Maven 3.0.1.
>> >
>> > Maybe you should have a look into the bash manual instead ?
>> >
>> > - Jörg
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> > For additional commands, e-mail: users-help@maven.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>

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


Re: Variables interpolated on the command-line

Posted by Sony Antony <so...@gmail.com>.
I think %myvar2% will result in windows shell doing teh substitution
I dont think maven will use system variables set using -D as pom variables (
maybe I m wrong )
--sony
On Thu, Apr 21, 2011 at 7:24 PM, Phillip Hellewell <ss...@gmail.com> wrote:

> This is on Windows from a command prompt, not Linux.
>
> Phillip
>
> On Thu, Apr 21, 2011 at 12:21 PM, Jörg Schaible <jo...@gmx.de>
> wrote:
> > Phillip Hellewell wrote:
> >
> >> Oh, I just thought of something shorter that will work:
> >>
> >> -Dmyvar1=c:\test\${myvar2}\.
> >>
> >> Still seems kinda crazy though.  Anyone want to shed some light on why
> >> it works this way?  This is with Maven 3.0.1.
> >
> > Maybe you should have a look into the bash manual instead ?
> >
> > - Jörg
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Variables interpolated on the command-line

Posted by Phillip Hellewell <ss...@gmail.com>.
This is on Windows from a command prompt, not Linux.

Phillip

On Thu, Apr 21, 2011 at 12:21 PM, Jörg Schaible <jo...@gmx.de> wrote:
> Phillip Hellewell wrote:
>
>> Oh, I just thought of something shorter that will work:
>>
>> -Dmyvar1=c:\test\${myvar2}\.
>>
>> Still seems kinda crazy though.  Anyone want to shed some light on why
>> it works this way?  This is with Maven 3.0.1.
>
> Maybe you should have a look into the bash manual instead ?
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

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


Re: Variables interpolated on the command-line

Posted by Jörg Schaible <jo...@gmx.de>.
Phillip Hellewell wrote:

> Oh, I just thought of something shorter that will work:
> 
> -Dmyvar1=c:\test\${myvar2}\.
> 
> Still seems kinda crazy though.  Anyone want to shed some light on why
> it works this way?  This is with Maven 3.0.1.

Maybe you should have a look into the bash manual instead ?

- Jörg


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


Re: Variables interpolated on the command-line

Posted by Phillip Hellewell <ss...@gmail.com>.
Oh, I just thought of something shorter that will work:

-Dmyvar1=c:\test\${myvar2}\.

Still seems kinda crazy though.  Anyone want to shed some light on why
it works this way?  This is with Maven 3.0.1.

Phillip

On Thu, Apr 21, 2011 at 11:51 AM, Phillip Hellewell <ss...@gmail.com> wrote:
> Some more interesting examples:
>
> xyz${myvar2}  => xyznull
> ${myvar2}xyz   => ${myvar2}xyz
> xyz${myavr2}xyz => xyz${mvar2}xyz
>
> so as long as I add something after, I can get it to not interpolate like I want
>
> So this is really ridiculous, but I've come up with something that works:
>
> -Dmyvar1=c:\test\${myvar2}\..\${myvar2}
>
> Phillip
>
> On Thu, Apr 21, 2011 at 11:39 AM, Phillip Hellewell <ss...@gmail.com> wrote:
>> I'm having trouble running a plugin I wrote and setting a variable to
>> another variable that I want to interpolate later.
>>
>> I've had success inside pom files by escaping the $ as $$, but from
>> the command-line that is not working.
>>
>> What's weird is that it is inconsistent about when it will interpolate
>> it or not, e.g.:
>>
>> mvn myplugin:mygoal -Dmyvar1=${myvar2}   => this sets myvar1 to
>> literally "${myvar2}", without interpolation
>>
>> mvn myplugin:mygoal -Dmyvar1="c:\test\${myvar2}"  => this one
>> interpolates it so I get myvar1 set to "c:\test\null"
>>
>> How can I make the second one work?
>>
>> Phillip
>>
>

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


Re: Variables interpolated on the command-line

Posted by Phillip Hellewell <ss...@gmail.com>.
Some more interesting examples:

xyz${myvar2}  => xyznull
${myvar2}xyz   => ${myvar2}xyz
xyz${myavr2}xyz => xyz${mvar2}xyz

so as long as I add something after, I can get it to not interpolate like I want

So this is really ridiculous, but I've come up with something that works:

-Dmyvar1=c:\test\${myvar2}\..\${myvar2}

Phillip

On Thu, Apr 21, 2011 at 11:39 AM, Phillip Hellewell <ss...@gmail.com> wrote:
> I'm having trouble running a plugin I wrote and setting a variable to
> another variable that I want to interpolate later.
>
> I've had success inside pom files by escaping the $ as $$, but from
> the command-line that is not working.
>
> What's weird is that it is inconsistent about when it will interpolate
> it or not, e.g.:
>
> mvn myplugin:mygoal -Dmyvar1=${myvar2}   => this sets myvar1 to
> literally "${myvar2}", without interpolation
>
> mvn myplugin:mygoal -Dmyvar1="c:\test\${myvar2}"  => this one
> interpolates it so I get myvar1 set to "c:\test\null"
>
> How can I make the second one work?
>
> Phillip
>

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