Command line -DjvmArgs not passed on to JVM

3,397 views
Skip to first unread message

LeoMaheo

unread,
Nov 15, 2009, 2:55:59 PM11/15/09
to Maven and Scala
Hi,

mvn scala:run -DjvmArgs=...
does not work for me.

The jvmArgs are not passed on to the JVM.

Am I doing something wrong, or is this a maven-netbeans-plugin bug?
(Plugin version: maven-scala-plugin:2.12.2.)

I do this:

mvn -DjvmArgs=-Xwhatever scala:run

It results in:
[INFO] cmd: /usr/lib/jvm/java-6-sun-1.6.0.16/jre/bin/java -classpath
[...] org.scala_tools.maven.executions.MainWithArgsInFile my.Main /tmp/
scala-maven-962809522626112964.args

This is what I'd expect: (notice the -Xwhatever)
[INFO] cmd: /usr/lib/jvm/java-6-sun-1.6.0.16/jre/bin/java -Xwhatever -
classpath [...] org.scala_tools.maven.executions.MainWithArgsInFile
my.Main /tmp/scala-maven-962809522626112964.args


(I'm trying to configure maven-scala-plugin to make the JVM debug-
connect to Netbean's debug server. I need to pass [the port number on
which Netbeans listens] on to the JVM. I suppose -DjvmArgs is what I
should use for this (but not a <jvmArgs> element in the pom.xml),
since Netbeans comes up with a new listen port each debug session.)


( Here is my maven-scala-plugin section in pom.xml.

<plugin>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.5</arg>
<arg>-g:vars</arg>
</args>
<displayCmd>true</displayCmd>
<launchers>
<launcher>
<id>runmain</id>
<mainClass>my.Main</mainClass>
</launcher>
</launchers>
</configuration>
</plugin> )

Thanks for any help,
Magnus

Josh Suereth

unread,
Nov 15, 2009, 5:03:39 PM11/15/09
to maven-a...@googlegroups.com
I'm not positive, but have you set the fork parameter to true?

David Bernard

unread,
Nov 15, 2009, 5:46:40 PM11/15/09
to maven-a...@googlegroups.com
@Magnus
You can't define jvmArgs from command line call of maven
see http://scala-tools.org/mvnsites/maven-scala-plugin/run-mojo.html#jvmArgs
doesn't define expression to allow command line override (not provide
by default for multi-value configuration parameters).
You could :
* define jvmArgs in the configuration section => shared by all forked process
* define jvmArgs in launcher section :

<launchers>
<launcher>
<id>runmain</id>
<mainClass>my.Main</mainClass>
<jvmArgs>
<jvmArg>-Xwhatever</jvmArg>
</jvmArgs>
</launcher>
</launchers>
As you define a launcher : set your jvmArgs


A side note, it's not a good practice to put <args> under
plugin/configuration if you define launcher,... : every configuration
entries define under plugin/configuration are shared by every goal =>
those args will be push to your launcher.

I suggest you rewrite your plugin section as :


<plugin>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>

<configuration>


<args>
<arg>-target:jvm-1.5</arg>
<arg>-g:vars</arg>
</args>

</configuration>


</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>

<displayCmd>true</displayCmd>
<launchers>
<launcher>
<id>runmain</id>
<mainClass>my.Main</mainClass>

<jvmArgs>
<jvmArgs>-Xwhatever</jvmArg>
</jvmArgs>
</launcher>
</launchers>
</configuration>
</plugin>

@Josh
forked is implicit for scala:run, and if process is not forked then
the line "cmd: ..." should not be displayed.

/davidB

LeoMaheo

unread,
Nov 15, 2009, 5:43:45 PM11/15/09
to Maven and Scala
Yes, it's set to true.
(It's true by default. I also set it explicitly to true, just in case,
but no effect.
If I set it to false my program won't compile.)

Thanks for the suggestion.

LeoMaheo

unread,
Nov 16, 2009, 5:01:41 PM11/16/09
to Maven and Scala
@David Bernard

Okay, that explains it all, thanks.

I've now added a <jvmArgs> section like so:
(notice the "${netbeans.listen.port}")

<launcher>
<id>debug.main</id>
<mainClass>my.Main</mainClass>
<jvmArgs>
<jvmArg>-Xdebug</jvmArg>
<jvmArg>-Xrunjdwp:transport=dt_socket,server=n,suspend=n,address=
${netbeans.listen.port}</jvmArg>
</jvmArgs>
</launcher>

and instructed Netbeans to define a Java system property,
netbeans.listen.port, when starting a debug session (via `mvn
scala:run ...').

(So now the debugee attaches to the Netbeans debugger, and I need
press no keys to instruct Netbeans to attach to the debugee. )

(I previously thought jvmArgs worked in the same way as addArgs, and
that all documentation hadn't been written yet, for jvmArgs (on that
page you linked). That is, I thought I could do something like this: -
DjvmArgs=-Dwhatever|-DwhateverMore|-DandMore. )


Thanks for the tips on placing <args> directly inside the <execution>
section, didn't know that was possible.


Regards, Magnus


On Nov 15, 11:46 pm, David Bernard <david.bernard...@gmail.com> wrote:
> @Magnus
> You can't define jvmArgs from command line call of maven
> seehttp://scala-tools.org/mvnsites/maven-scala-plugin/run-mojo.html#jvmArgs

David Bernard

unread,
Nov 17, 2009, 3:38:33 AM11/17/09
to maven-a...@googlegroups.com
> Thanks for the tips on placing <args> directly inside the <execution>
> section, didn't know that was possible.

It's possible and should word, but it seems to not working currently
(on my office configuration) I'll investigate why.
Contribution to doc or wiki/faq are welcome.
I'll add the "tips" to the doc (if I'll don't forget).

/davidB
Reply all
Reply to author
Forward
0 new messages