Remote debugging capability with different debuggers( IDEs) are nice features for developers. Purpose of this blog is to share this information that how to
use remote debugging tools effectively. Here i tried to give example for eclipse IDE.
Remote debugging in eclipse can be done in two ways:
a) Socket Attach
b) Socket Listen
Socket Attach: For e.g. we want to debug an application which is deployed on tomcat and we want to debug that. Attach the application process through eclipse once we start our tomcat in debug mode.
Step 1:
How to start tomcat in debug mode:
$./catalina.sh jpda start (in case of unix based machines) or
> catalina.bat jpda start ( in case of windows based machines)
This is going to start a tomcat in debug mode and a socket with port as 8000 can be attached to it.
In case if user wants to attach to different port than following can be done.
export JPDA_ADDRESS=8000 (in case of unix based machines)
$./catalina.sh jpda start
set JPDA_ADDRESS=8000 (in case of windows based machines)
> catalina.bat jpda start
Step 2:
Open debug configuration on eclipse and add new Remote Java Application.
Connection Type should be Standard (Socket Attach). Give a host name or ip in the value for Host in connection properties where the remote process is running.
For e.g.
For Other application server like WebSphere:
Open admin console and open Servers->Server Type -> WebSphere Application Servers.
Than choose your server from the list of available servers. And than select Debugging service.
for e.g:
Application servers > server1 > Debugging service
Make check box "Enable service at server startup" as selected.
default port for debug is 7777, change it if you want to debug on different port.
Restart the server and attach your debugger ( IDE or eclipse) to it.
Socket Listen: When we want to start a listener first and the remote application is required to be attached to the eclipse
debugger, in that case. First we need to start the eclipse debugger in Socket Listten mode and attach the application.
Step 1:
Open debug configuration in eclipse and add new Remote Java Application.
Connection Type should be Standard (Socket Listen).
Port in connection properties should be 8000 if you want remote application should connect using this port value.
For e.g.
Step 2:
Options a) if wants to debug with ant than in your build.xml add
<jvmarg line="-Xdebug -Xrunjdwp:transport=dt_socket,address=10.240.1.14:8000,server=n" /> for e.g.
Java -Xdebug -Xrunjdwp:transport=dt_socket,address=10.240.1.14:8000 -jar MyJar.jar
Options c) if you wants to debug a application which is again an eclipse ( or eclipse based plugins) than you can start the eclipse application as
eclipse.exe -vmargs -Dosgi.requiredJavaVersion=1.6 -Xms256m -Xmx512m -Xdebug -Xrunjdwp:transport=dt_socket,address=10.240.1.14:8000,suspend=n
10.240.1.14 IP where you want to debug and where your debugger is running.
Debugging in JBoss can be debugged by modifying JAVA_OPTS in the file which is used to start the server in the similar way as mentioned above.
IBM WebSphere is already explained above.
Remote debugging in eclipse can be done in two ways:
a) Socket Attach
b) Socket Listen
Socket Attach: For e.g. we want to debug an application which is deployed on tomcat and we want to debug that. Attach the application process through eclipse once we start our tomcat in debug mode.
Step 1:
How to start tomcat in debug mode:
$./catalina.sh jpda start (in case of unix based machines) or
> catalina.bat jpda start ( in case of windows based machines)
This is going to start a tomcat in debug mode and a socket with port as 8000 can be attached to it.
In case if user wants to attach to different port than following can be done.
export JPDA_ADDRESS=8000 (in case of unix based machines)
$./catalina.sh jpda start
set JPDA_ADDRESS=8000 (in case of windows based machines)
> catalina.bat jpda start
Step 2:
Open debug configuration on eclipse and add new Remote Java Application.
Connection Type should be Standard (Socket Attach). Give a host name or ip in the value for Host in connection properties where the remote process is running.
For e.g.
For Other application server like WebSphere:
Open admin console and open Servers->Server Type -> WebSphere Application Servers.
Than choose your server from the list of available servers. And than select Debugging service.
for e.g:
Application servers > server1 > Debugging service
Make check box "Enable service at server startup" as selected.
default port for debug is 7777, change it if you want to debug on different port.
Restart the server and attach your debugger ( IDE or eclipse) to it.
Socket Listen: When we want to start a listener first and the remote application is required to be attached to the eclipse
debugger, in that case. First we need to start the eclipse debugger in Socket Listten mode and attach the application.
Step 1:
Open debug configuration in eclipse and add new Remote Java Application.
Connection Type should be Standard (Socket Listen).
Port in connection properties should be 8000 if you want remote application should connect using this port value.
For e.g.
Step 2:
Options a) if wants to debug with ant than in your build.xml add
<jvmarg line="-Xdebug -Xrunjdwp:transport=dt_socket,address=10.240.1.14:8000,server=n" /> for e.g.
<target name="execute" description="Test"> <java classname="${main.class}" fork="true" failonerror="true"> <classpath refid="class.path" /> <arg value="${myargument}" /> <jvmarg value="${myjvmargument}" /> <jvmarg value="-Xrs" /> <jvmarg line="-Xdebug -Xrunjdwp:transport=dt_socket,address=10.240.1.14:8000,server=n" /> </java> </target>Option b) If you wants to debug with .bat file or on command prompt
Java -Xdebug -Xrunjdwp:transport=dt_socket,address=10.240.1.14:8000 -jar MyJar.jar
Options c) if you wants to debug a application which is again an eclipse ( or eclipse based plugins) than you can start the eclipse application as
eclipse.exe -vmargs -Dosgi.requiredJavaVersion=1.6 -Xms256m -Xmx512m -Xdebug -Xrunjdwp:transport=dt_socket,address=10.240.1.14:8000,suspend=n
10.240.1.14 IP where you want to debug and where your debugger is running.
Debugging in JBoss can be debugged by modifying JAVA_OPTS in the file which is used to start the server in the similar way as mentioned above.
IBM WebSphere is already explained above.