Debugging is one of the most uesful tecnique for troubleshooting, but when you are working with distributed systems it could be uncomfortable to setup a debug environment on your machine. Fortunately, Java supports remote debugging that could help in this scenarios.

Remote debugging works extacly like local debugging. Run the application in debug mode on the server and attach the IDE debugger to it, and you will be able to debug your app remotely on your IDE.

I tried this process on Netbeans with a Spring Boot web application and it's a pretty simple process.

First thing, after created the jar package, run it with this command:

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8123,suspend=n -jar target/myproject.jar

Then open Netbeans and attach the debugger to the server from this menu

Debug > Attach debugger...

And fill the next window with the right parameters, pay attention to "host" and "port" debugging image

Anyway while this tecnique is accetable for development/staging process it will be a seriuos security issue in the production environment because opening the port without encryption and authentication will enable anyone to connect to your jvm.

References

Remote debugging - Oracle Documentation Stackoverflow - About security

Next Post Previous Post