Tai
Tai

Reputation: 1256

Debugging in maven with mvnDebug command

I read this: Debugging in Maven?

I'm running intellij remote debug and maven for a service I'm trying to debug.

I'm running

mvnDebug tomcat7:run 

Which gives me the following result

Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000
^Ctai-m:sb-api-internal-server tai$ m

My problem is that I want to change the port easily. I know that I can go into the pom.xml file and change it or that I can do the following in:

mvnDebug.bat

@REM set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000

but I want to be able to specify my port on the command line. Is there any way to do this? I want to be able to debug multiple services on different addresses running at once and am under the impression that it would be a hassle to have to set and reset the debug file setting for each one.

A friend said it should be possible but I can't seem to find a solution.

Essentially Im looking for a way to easily switch the port a service is running on hopefully without modifying a file multiple times as I launch multiple services. Otherwise Is there another solution you can thing of? Ex having the first debug instance running on one port and then having the second on another (hard coded)?

Thanks

Upvotes: 8

Views: 25308

Answers (3)

winson huang
winson huang

Reputation: 21

Another answer under the question you mentioned is https://stackoverflow.com/a/2935474/19955141 . I think that solution match your need, just use exec goal in exec plugin:

mvn exec:exec -Dexec.executable="java" -Dexec.args="-classpath %classpath -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 com.mycompany.app.App"

You can modify the address value to set port.

Upvotes: 0

Neal Bamford
Neal Bamford

Reputation: 11

I changed @set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000

to

@set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%MAVEN_DEBUG_PORT%

in mvnDebug.cmd then either set MAVEN_DEBUG_PORT in env variables or locally with set @set MAVEN_DEBUG_OPTS=8001 before you call mvnDebug xxx:run (I'm using Jetty)

Upvotes: 1

Kevin Condon
Kevin Condon

Reputation: 1728

Wow, Maven makes this difficult. Setting -Xrunjdwp in MAVEN_OPTS won't work, because mvnDebug.bat adds its own afterward, which will override MAVEN_OPTS. I would copy mvnDebug.bat to myMvnDebug.bat and comment out the line set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000. That way you can set MAVEN_DEBUG_OPT on the command line before running it.

C:\somewhere>set MAVEN_DEBUG_OPT=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8001
C:\somewhere>myMvnDebug.bat

Upvotes: 7

Related Questions