It's an important feature that JVM provided and I'm so surprised that I used it at the first time today.
To enable it, you will just need to add below JVM arguments in command line:
Then you can use your debugger to attach to remote JVM.
suspend is quite useful argument here. If
y, JVM will suspend before main class is loaded until debugger attach to it.
y if you need to debug application initialization phase.
I believe all IDEs have that function to debug Java application remotely. I use IntelliJ here for demonstration.
Add a new configuration under Remote category, you will see IntelliJ provides command line arguments for you. That's exactly what I show in previous section.
Change the host to your server's url, and launch your application with remote debug arguments, then you can debug as what you did on debugging local application.
And remember, DO NOT REMOTE DEBUG YOUR PRODUCTION APPLICATION