3

I am trying to debug a Maven jetty project in eclipse. I am staring jetty using "mvn clean jetty:run". Here's the complete bat file I'm using (I'm on windows).

set MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n"  
mvn clean jetty:run

I am using the jetty-maven-plugin inside the pom file.

The bat file works ok and starts jetty without errors. Inside eclipse, I created a new debug configuration, chose "Remote Java Application" and I used 4000 for the port and localhost for the host.

When I try to run this debug configuration, I always get this error:

"Failed to connect to remote VM. Connection refused.
Connection refused: connect"

Does anyone know how I can solve this? I checked this answer, but it did not help.

Community
  • 1
  • 1
dcp
  • 51,027
  • 19
  • 136
  • 157

2 Answers2

3

The solution was that you have to change it to suspend=y instead of n in the MAVEN_OPTS. Then you do the mvn jetty:run command, and it will pause at the "Listening for transport dt_socket at address: 4000" line. After that, you run the eclipse debugger and it will attach to the process.

If you use suspend=n, it won't work (at least for me it didn't).

dcp
  • 51,027
  • 19
  • 136
  • 157
  • I get "Listening for transport dt_socket at address: 9000" message when I start jetty. But after that If I try to run the debug configuration. It gives me `Failed to connect to remote VM. Connection refused. Connection refused: connect`. And my port is not used by any other application. – Lucky Apr 05 '16 at 15:31
0

You can change your (maven_folder)/bin/mvn.bat ( or sh) and put the line you mentioned.

set MAVEN_OPTS="%MAVEN_OPTS% -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n" 

Depending on your maven version there's a mvnDebugg file that will do this for you, in this case the debbug port will be 8000

Tiago Engel
  • 3,168
  • 1
  • 15
  • 21
  • I don't really want to modify the mvn.bat file, as the whole point of it is that you sent MAVEN_OPTS *outside* of that file, and then mvn.bat would then use the MAVEN_OPTS you already have set. And that still wouldn't have anything to do with the connection refused problem. – dcp May 05 '14 at 20:22
  • Well, setting this outside don't work for me, maybe you need to do a export (don't know how to do this on windows). If you don't want to change the file, you can create a mvnDebug.bat and put the debug line on it. And then run mvnDebug jetty:run – Tiago Engel May 05 '14 at 20:33
  • If the debug opts are not passed to the JVM the error will be Connection refused, you can check in the console, it will show "Listening for transport dt_socket at address: 4000" – Tiago Engel May 05 '14 at 20:42
  • I get the "Listening for transport dt_socker at address: 4000" message on the console. However, I still get the error connection error in eclipse when trying to run the debug configuration. I tried adding the MAVEN_OPTS to the mvn.bat, but it made no difference. – dcp May 05 '14 at 20:50
  • Maybe this port is in use or blocked, maybe change the port will work. Or disabling any kind of firewall and anti-virus. You can try to mark the mnv.bat to run as administrator too. – Tiago Engel May 05 '14 at 21:08