maven and path variables issue

I am trying to create a path variable VM_PARAMS with a value of :

-Dprop1=v1 -Dprop2=v2 -D.....

I got a lot of properties and I need them in 1 place.

Now I can use this variable to create java run configurations. $VM_PARAMS$ is expanded correctly and the -D args are passed to my java code.

When I try to do the same with mvn run configs, I get in trouble. $VM_PARAMS$ is not replaced with my path variable value and ${VM_PARAMS} is expanded to "-Dprop1=v1 -Dprop2=v2 ..." (including the double quotes). So mvn runs like

mvn ... "-Dprop1=v1 -Dprop2=v2 ..." ...

and the -D properties are not passed to my code.

Is there a way to make this work?

6 comments
Comment actions Permalink

It sounds like in your maven run configuration you are putting the $VM_PARAMS$ in the "Command line" text field n the parameters tab. It should go in the "VM Options" text field on the runner tab.

If that is not it, can you please better describe your maven run configuration. Perhaps a screenshot of each of the three tabs.
0
Comment actions Permalink

I am using $VM_PARAMS$ in the mvn config's Runner->VM Options. What I get when I run the config:

.../jdk1.7.07/bin/java $VM_PARAMS$ .......
Error: Could not find or load main class $VM_PARAMS$

Process finished with exit code 1


If I use ${VM_PARAMS} I get VM_PARAMS within double quotes:

.../jdk1.7.07/bin/java "-Dp1=.... -Dp2=.... -D...." ...

and my code can't read p1,p2 (System.getProperty)

0
Comment actions Permalink

hmmm... ${VAR_NAME} is the correct syntax. Not to state the obvious, but we've all been guilty of such silly errors... have you double checked that the quotes are not in your variable's value? I assume you are probably OK since you said it works for a java run configuration. It's only the maven one that is giving you issues. But it never hurts to double check.

What version of IntelliJ IDEA? If you are not running the latest (11.1.5 or 12.0.1), try upgrading. This works fine for me on 12.0.2 EAP build 123.100 (on Windows). I think I remember in the release notes of a release a while back there being something about a bug fix in regards to quotes and variable substitution.

If the above does not work, as a workaround while you are trying to resolve the issue, can you put your property definitions into your MAVEN_OPTS system variable? It would be used by all maven executions on your system. But if it gets you moving forward and doesn't break other maven executions, it's something.

Shy of that, I'm sorry to say I personally am out of ideas.

0
Comment actions Permalink

${VAR_NAME} is the correct syntax but it adds the double quotes
(I think if the variable contains spaces). My variable value isn't enclosed in double quotes.

Using $VAR_NAME$ avoids the double quotes (when it works!)

But I think there is a bug in maven run configurations Variables don't seem to work at all in "Working directory" and have the issues described in the rest of the edit boxes. $VAR$ doesn't work in "VM Options"

The double quotes might actually work for windows but doesnt do the trick in my linux box.

I am using the latest IDEA 12.0.1 IC123.94

0
Comment actions Permalink

ariskk wrote:

${VAR_NAME} is the correct syntax but it adds the double quotes
(I think if the variable contains spaces).

That is indeed what it is doing:
Given:
FOO=ABC
BAR=X Y Z
Using
${FOO} ${BAR}
results in
...java ABC "X Y Z"

I suggest you open a feature request asking for an option to not surround with quotes env/system variable with spaces.

0

Please sign in to leave a comment.