Nwn
Nwn

Reputation: 571

Unable to open debugger port for Spring boot debug with intelliJIdea

I want to debug a Spring boot application with IntelliJ. I'm using windows 10. when I run my spring boot project with following command it works fine. But debugging not working.

mvn spring-boot:run -Drun.profiles=dev -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

And then I make a remote debugger with intelliJ as follows.

enter image description here

but when I click the debug button intelliJ shows following message.

Error running 'RemoteDeBugger': Unable to open debugger port (localhost:5005): java.net.ConnectException "Connection refused: connect

What is the reason for above behavior and how to do debugging correctly.

Upvotes: 6

Views: 19343

Answers (2)

Viacheslav Plekhanov
Viacheslav Plekhanov

Reputation: 411

In newest versions of IntelliJ IDEA just choose "Remote" option in configurations and fill you host. Then copy JVM command line arguments to remote JVM like it described in Philippe Simo's answer. enter image description here

Upvotes: 0

Philippe Simo
Philippe Simo

Reputation: 1459

What is the reason for above behavior?

You have this error because your remote debugger is looking to a JVM listening to the port 5005.

how to do debugging correctly?

You have to run such a JVM first, i mean with the port 5005. Well, to do it, you already have the answer:

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"

or

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"

Using agentlib:jwdp is better as specified from the Documentation

From 5.0 onwards the -agentlib:jdwp option is used to load and specify options to the JDWP agent. For releases prior to 5.0, the -Xdebug and -Xrunjdwp options are used (the 5.0 implementation also supports the -Xdebug and -Xrunjdwp options but the newer -agentlib:jdwp option is preferable as the JDWP agent in 5.0 uses the JVMTI interface to the VM rather than the older JVMDI interface).

After everything started up successfully, you can then launch your configured remote debugger by clicking on debug.

Make sure you use the same port than the one used for running the app.

You will be at that time good to start analyzing your code from breakpoints.

Upvotes: 12

Related Questions