Friday, April 2, 2010

Remote debugging Tomcat with Eclipse

Remote debugging Tomcat with Eclipse


I have tried to use tomcat remote debugging using Eclipse.

To run tomcat in remote debugging you can start using below command
catalina jpda start

This (above command) will start remote debugging using shared memory, and Eclipse, as far as I know, does not support shared memory as transport for debugging.

The alternative way is to use a socket as transport for JPDA.

You simply set of some environment variable that will be checked by catalina startup script.

This tells that tomcat will use socket transport for debugging and listen on port 5050. If you don't specify the port, it will be assigned randomly.
set JPDA_TRANSPORT=dt_socket
set JPDA_ADDRESS=5050

And then start catalina.
D:\tools\apache-tomcat-6.0.18\bin>catalina jpda run
OR
D:\tools\apache-tomcat-6.0.18\bin>catalina jpda start

When tomcat started, you'll see some messages on console saying that debugging socket is listening.
C:\Tools\apache-tomcat-6.0.18\bin>catalina jpda run
Using CATALINA_BASE:   C:\Tools\apache-tomcat-6.0.18
Using CATALINA_HOME:   C:\Tools\apache-tomcat-6.0.18
Using CATALINA_TMPDIR: C:\Tools\apache-tomcat-6.0.18\temp
Using JRE_HOME:        C:\SDK\jdk
Listening for transport dt_socket at address: 5050
Apr 2, 2010 4:26:32 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performanc
e in production environments was not found on the java.library.path: C:\SDK\jdk\
bin;.;C:\WINDOWS\system32;C:\WINDOWS;"";
Apr 2, 2010 4:26:32 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Apr 2, 2010 4:26:32 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 423 ms
Apr 2, 2010 4:26:32 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Apr 2, 2010 4:26:32 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
Apr 2, 2010 4:26:32 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Apr 2, 2010 4:26:33 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Apr 2, 2010 4:26:33 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31  config=null
Apr 2, 2010 4:26:33 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 958 ms

Now it's time to connect to that socket using Eclipse:

Open eclipse, goto Run - Debug Configurations, give name, select Project, Connection Type, and give connection properties like below.



That's it!!!, Now you can do normal debugging process.

Copyright - There is no copyright on the code. You can copy, change and distribute it freely. Just mentioning this site should be fair

(C) March 2010, manivelcode

No comments: