1

I have a tomcat running after making configuration and when I type jdb in terminal it says initializing. So I like to know

  1. How to attach jdb with tomcat and specify servlet name.

  2. What is the compile option (like in C its eg. -g with gdb) to include debugging symbols when compiling servlet with javac

I have opt/tomcat/apache-tomcat-10.0.10 so I guess Tomcat version is 10

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user786
  • 3,902
  • 4
  • 40
  • 72
  • how to attach to -> `.class` <- file and tomcat to jdb believe its a binary file like `.o` in C C++ – user786 Aug 25 '21 at 15:07

1 Answers1

0

The javac command switch to add all debugging symbols is ... -g. Line numbers and source file names are actually added by default, you only gain information on local variables (see this question).

You can not connect a debugger to a running JVM, unless it was started with the appropriate command line option (see this question).

Tomcat has a helper script bin/catalina.sh that can help you start it with the correct parameters:

  • catalina.sh jpda start starts Tomcat in the background with debugging enabled. You can connect to it with:

    jdb -attach localhost:8000
    
  • catalina.sh jpda run works as in the previous case, but in the foreground,

  • catalina.sh debug starts Tomcat through jdb. You just need to use run to start it.

Once you are connected you can use:

stop in <class id>.<method>

to add break points.

Remark: Both javac and jdb are not often used these days. Most people use tools like Ant, Maven, Gradle, etc. to compile their projects and IDEs to debug the code.

Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43