7

rI want to run jetty:run in debug mode with MAVEN_OPTS setted in environment variable. But it seams like hardcode MAVEN_OPTS. Is it possible to set MAVEN_OPTS in command line like mvn MAVEN_OPTS=...

Thank you.

Andy
  • 8,841
  • 8
  • 45
  • 68
robinmag
  • 17,520
  • 19
  • 54
  • 55

4 Answers4

18

Is it possible to set MAVEN_OPTS in command line like mvn MAVEN_OPTS=...

No, MAVEN_OPTS is an environment variable, you can't set it on the command line. But you there is an alternative. Instead of mvn, you can simply run mvnDebug (a little variation of the former script that set debug options):

$ mvnDebug jetty:run
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000

I find this alternative pretty handy, and easier.

Andy
  • 8,841
  • 8
  • 45
  • 68
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
7

Under Windows - I don't know. Under Linux/Bash - yes you can:

export MAVEN_OPTS="-Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
mvn jetty:run
Grim
  • 1,938
  • 10
  • 56
  • 123
Henryk Konsek
  • 9,016
  • 5
  • 32
  • 41
  • I don't see any advantage over using `mvnDebug` if you use the same options. – Pascal Thivent Sep 29 '10 at 15:43
  • The question explicitly refers setting environment variable and running Maven with one command. I'm not telling it's better than mvnDebug :) . – Henryk Konsek Oct 01 '10 at 05:52
  • On Linux Ubuntu 16.04 running this command followed by the mvnDebug one gives me the error `Cannot load this JVM TI agent twice`. – Stephane Jul 08 '18 at 20:45
4

Under Windows you should be able to do the following from the command prompt:

set MAVEN_OPTS=<options you want to add> %MAVEN_OPTS%
mvn jetty:run

Under Mac/Linux/Unix you can use export from the Terminal:

export MAVEN_OPTS=<options you want to add> $MAVEN_OPTS
mvn jetty:run

Not sure about how to do single use exports in Windows, but on Unix like operating systems you can just prepend the variable to your command (this works for any environment variable you want to add).

MAVEN_OPTS="option1 option2" mvn jetty:run
rharter
  • 2,495
  • 18
  • 34
3

I encountered this problem, and my solution was to create a .bat file to set the maven opts, and then start jetty.

call set MAVEN_OPTS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8484,server=y,suspend=n %MAVEN_OPTS%
call mvn jetty:run-war -DskipTests=true

My IDE of choice is Eclipse, so I use the run button with the tool box to call the .bat files. Here is a question on running a .bat file.

Community
  • 1
  • 1
Andy
  • 8,841
  • 8
  • 45
  • 68