Remote debugging Tomcat with Eclipse

Today I tried to use remote debugging with Eclipse and Tomcat.
I usually use a Tomcat Sysdeo Plugin to run Tomcat inside Eclipse, but today I faced remote debugging.
To run tomcat in remote debugging you can start it with command
catalina jpda start

But this will start remote debugging using shared memory, and Eclipse, as far as I know, does not support shared memory as transport for deubugging.
The alternative is to use a socket as transport for JPDA.
You simply set some enviroment variable that will be checked by catalina startup script, as in following example:

set JPDA_TRANSPORT=dt_socket
set JPDA_ADDRESS=5050
... then you can run ...
D:\Java\jakarta-tomcat-5.5.7\bin>catalina jpda run
...or...
D:\Java\jakarta-tomcat-5.5.7\bin>catalina jpda start

This tells catalina script to use socket transport for debugging and to listen on port 5050. If you don't specify the port, it will be assigned randomly.
When you start tomcat, you'll see some messages on console saying that debugging socket is listening:

D:\Java\jakarta-tomcat-5.5.7\bin>catalina jpda run
Using CATALINA_BASE:   D:\Java\jakarta-tomcat-5.5.7
Using CATALINA_HOME:   D:\Java\jakarta-tomcat-5.5.7
Using CATALINA_TMPDIR: D:\Java\jakarta-tomcat-5.5.7\temp
Using JAVA_HOME:       d:\Java\jdk1.5.0_04
Listening for transport dt_socket at address: 5050
4-ott-2005 18.26.11 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
4-ott-2005 18.26.11 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1162 ms
4-ott-2005 18.26.11 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
4-ott-2005 18.26.11 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.7
4-ott-2005 18.26.11 org.apache.catalina.core.StandardHost start

Now it's time to connect to that socket using Eclipse: see following picture.

Eclipse Remote Debugging

On "Connection Properties" you can configure a remote VM that you want to debug. Then place your breakpoints and run the shown launch configuration.
Shared memory is easier to be used: with tomcat you don't have to set up environment variables, and for IDE supporting it (I used this with IntelliJ), you only need to specify the name of the shared space. This won't work if the VM to debug is on a remote computer but can be helpful anyway. I tried to find shared memory support in Eclipse but I didn' find it, and I believe it doesn't have.
Remote debugging is more useful when you have to attach to a running instance on a remote server on which the bug is alive. Shared memory support lack is not that problem.

One thing that you cannot do running programs inside Eclipse under Windows is to get a Thread dump. On Windows you can get a Thread Dump pressing CTRL+Break in the DOS console, but this doesn't work on Eclipse console. On Linux you can use "kill -3", and I think this work even running processes in Eclipse. Maybe it's possible also in Windows, using some esotic tool, but I don' know... also I don't know if Windows supports several kill signals.


11 Commenti a “Remote debugging Tomcat with Eclipse”  

  1. 1 ravi

    the steps and the explanation provided are very vague. isnt there a site that gives a detail view into the issue.

    i m trying to debug a tomcat in the linux box from a win xp box. when i put the paramters as specified here the tom cat doesnt start up at all.! any ideas

    do we need to include some jar in classs path or any other??

    cheers,
    ravi

  2. 2 Richard

    At last I can remote debug my web app in tomcat 5.5 with eclipse - why are these options not made more visible or scripted? so simple when running under JBoss but tomcat on its own seems to make life that little bit more difficult.

  3. 3 bagman

    Excellent post! I am doing schoolwork with eclipse ganymede and the buggy bitch will not deploy my project properly to the internal server and will not connect to the internal server even tho it seems to be running. Matter of fact it will not connect to any web service internally: can’t access help either. I love eclipse 18M lines of code delivered on time and full of bugs.

  4. 4 DMM

    Hey,

    That was very helpful. Better than all publications on debugging i see lately.
    Thanks!

    Regards,
    D

  5. 5 Pedro75

    Hi I used your procedure to debug a webservice (axis2 and tomcat). I installed breakpoint on sekeleton (webservice side) but I receive this message: “Unable to install breakpoint in ‘project name’ due to missing line number attributes…”

    I checked on eclipse window/preference/java/compiler and all the options are correctly flagged.

    Can anyone help me?

    Thanks

  6. 6 Luigi

    Hi Pedro.

    Probably your class files are compiled without debugging information. Ensure that javac (java compiler) is not invoked specifying any option to suppress debug informations in class files. Check also ant/maven or the other tools you are using to compile your classes. Definitely the problem is in the class files.

  7. 7 pedro75

    Hi Luigi, I check my build.xml file (I generate the .class by ant) as you suggested and tag had the field debug=”false”. Now this field is “true” and all works: now I can debug in remote… Thank you very much….

  8. 8 Paul

    Thanks, that was very helpful !!!

  9. 9 Shivam

    Excellent post..I was able to debug my stuff.Keep it up..

  1. 1 关于Eclipse和IntelliJ IDEA整合Tomcat调试 - Kappa’s fresh life
  2. 2 Fare il debug di web services « Software Libero e non solo


Lascia un Commento

XHTML: Puoi utilizzare questi tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Calendario

Ottobre 2005
L M M G V S D
« Set   Nov »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Categorie