Have you ever had the need to debug a Java application remotely? You can! This post describes how you can do using Java and Eclipse.
Let’s start by describing some important Java remote debugging parameters that we’ll make use of later.
- transport=dt_socket instructs the JVM that the debugger connections will be made through a socket
- address=8998 opens port number 8998 for use by the debug session
- suspend=y starts the JVM in suspended mode and remains suspended until a debugger is attached to it
Now that we have that under our belt, let’s get to the good stuff…
1. Start an application for remote debugging:
The command line below will cause the application to listen for a debug connection on port 8998. The application will start ‘suspended’ and will ‘resume’ once a debugger has attached.
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=y,address=8898 MyApplication
2. Start an eclipse application for remote debugging:
eclipse.exe -vmargs -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8998
Using the Eclipse Debug configuration wizard, we can create a ‘Remote Java Application’ debug configuration. This can be configured to attach to a remote java application started using JPDA.