Wednesday, September 14, 2011

Remote Debugging In Eclipse

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:
$./ 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)
$./ 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=,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=,server=n" />

Option b) If you wants to debug with .bat file or on command prompt

Java -Xdebug -Xrunjdwp:transport=dt_socket,address= -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=,suspend=n 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.

No comments:

Post a Comment