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.
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.
If the code is outdated, or the versions (the source code and the compiled class) mismatch in any way, it can happen that the debugged is giving the IDE information to show a certain line, but that information is not correct giving the current source code, which might cause what appears to be the debugged "jumping" ...
Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Debugger. In the Built-in server area, specify the port where the built-in web server runs. By default this port is set to the default IntelliJ IDEA port 63342 through which IntelliJ IDEA accepts connections from services.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With