6

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.

Nwn
  • 561
  • 2
  • 9
  • 33
  • Try using some other port number, see if the app is listening for the debugger connection on the specified port using TcpView. – CrazyCoder Jul 10 '18 at 08:53
  • I think no. Seems even though I started the application in debug mood it doesn't started in debug mode. I tried with deference port numbers – Nwn Jul 10 '18 at 09:38
  • 2
    Did you check https://stackoverflow.com/a/50677882/104891? – CrazyCoder Jul 10 '18 at 10:46

2 Answers2

12

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.

Philippe Simo
  • 1,353
  • 1
  • 15
  • 28
  • 2
    don't know why it has been down voted when the answer is perfectly addressing the question. Down voting without giving proper reason is against the good will of this community. – xpioneer Feb 02 '20 at 17:30
  • Finally, something that works. The -Drun.profiles=dev version is the one I tried and it worked. Thanks! – Sanjeev Dwivedi Feb 10 '20 at 07:46
0

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