Remote debugging Tomcat with Eclipse
I spent some time on this to get the right information.
So here is the detailed information step by step.
Environment : Windows 7
TomCat version : 7.0
IDE : Eclipse
Configurations to be added for enabling remote debugging with in tomcat is
-Xdebug
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
I don't recommend above configuration fro non windows environment. To add the above configuration double click on tomcat server which will be available in server view. Find the below screen shot.
Now add the above runtime environment configuration to tomcat. For this check below screenshot.
Now got to Arugments tab in Edit launch configuration properties as show in below screen shot.
GoTo VM arguments section add these lines.
-Xdebug
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
Now got to debug button available on eclipse toolbar.
In Debug configurations find "Remote Java Application" and double click on it.
In Name field enter any name which you like to.
From project field using browse button select the project which you want to perform remote debug.
The hostname is nothing but the host address. Here i'm working locally so it is "localhost".
Last the Port column the value should be 8000. Apart from Name and Project text fields other two columns Host and port will be filled by eclipse itself if not make you have same values as mentioned. Check Screen shot for info.
Now right click on TomcatServer in server console select Add and Remove from context menu. From this dialog you can add the project to server.
Now run the Tomcat sever.
Now run the TomCatDebugConfiguration from Debug Tool.
Last open internal or external browser and run your project. If the execution control reached the break points then the eclipse will prompt for debug perspective.
In the tomcat bin directory wherecatalina.bat
or .sh
is found (aka {CATALINA_BASE}/bin), edit (create if not there):
setenv.bat/.sh
Add the following line:
CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
That's all you need to do, you don't need to edit the catalina.bat
(or .sh
) file.
See the comments in catalina.bat
or catalina.sh
.
You may have to adjust the syntax for your particular environment/situation. For example, if you already have CATALINA_OPTS defined, you might do something like this (in a windows environment):
set CATALINA_OPTS=%CATALINA_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,address=8088,server=y,suspend=n
To debug from Eclipse:
run->Debug configurations...->Remote Java Application->New
and specify a name, the project you are debugging, and the tomcat host and debug port specified above.
Can you check if this works?
JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"
catalina.sh jpda start