How to start Tomcat 6 in debug mode when run as a service on RHEL

Dean Schulze picture Dean Schulze · Dec 7, 2012 · Viewed 14.8k times · Source

This should be easy, but I can't get debugging to work on Tomcat 6 when it is running as a service on RHEL 6.1.

I've added the following line to /etc/tomcat6/tomcat6.conf

JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

When I restart the tomcat 6 service with

service tomcat6 restart

the command line indicates that Tomcat shutdown and started, but it is not running and when I look in the catalina.out log I see

ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options.
Error occurred during initialization of VM
agent library failed to init: jdwp

Attempting to restart the Tomcat6 service fails for both shutdown and startup. I have to reboot RHEL.

I thought that maybe Tomcat6 is running in debug mode by default, but when I comment out the line in tomcat6.conf and reboot using netstat -an doesn't show anything using port 8000 or any port in use by Tomcat.

Can Tomcat 6 be run in debug mode when it is run as a service?

Answer

sambatha picture sambatha · May 3, 2013

Just Check the PORT number 8000 available in the Catalina.sh file . And Check is there any process run in same PORT number 8000.

If any process running in same port then stop the process and run the jpda.

Check the env variable in the same address. catalina.sh file shell script clearly tell that it use port 8000 to execute it.

If you like to change the port address and set in your .bashrc file as

export JPDA_ADDRESS=8009

and execute the command

$ ./catalina.sh jpda run (it's for ordinary method)

If you have run with Security manager then

$ ./catalina.sh jpda run -security

and Go to Eclipse

Go to -> Debug Configuration

Configuring Eclipse to remote debugging

First of all, we have to open or import the project with the source code of the application we want to debug. Afterward we have to setup the debug from Eclipse:

1) Clicking on the right side (arrow facing to above) of the “Debug” button (the button with the bug) that is in the toolbar and the clicking on “Debug configurations…” or in the menu Run > Debug configurations… Then a new window with the different debug configuration will be opened.

Debug configuration

2) Select “Remote Java Application” in the left menu and then press on “New launch configuration” button (the button with the folder icon in the top-left corner).

New debug configuration

3) Fill the configuration with the data corresponding with our Tomcat instance:

Project: The project we want to debug: it has to contain the source code for the application we want to debug.
Connection Type: Standard (Socket Attach).
Host: IP of the server in which is Tomcat installed.
Port: Port indicated to JVM in address parameter. Port 8000 in our example

Eclipse nothing displays . No changes are shown in eclipse.

Just set Breakpoints in eclipse where you needed and go and run the application in tomcat .

!!!!!! Successfully Debug mode will working !!!!!!!!!

Congratzzzzz!!!!!

By sampath