This blog is subject the DISCLAIMER below.

Wednesday, November 26, 2008

Enabling Remote Debugging for tomcat

Sometimes your web application just works very fine on your local machine and when you move it to the deployment environment you see a BOOM. If the deployment environment is a Non-GUI machine (which is the common case), it is very hard to debug on that machine. Simply all what you need is to use a remote debugger to connect to the server machine and see what is wrong.

The concept is that you enable the web server to start the JVM in debug mode and start listening on a certain port for remote debuggers to connect, in tomcat, all what you need to do is to add this line to the
you will find at the begining of the file a set of lines started by "#" as they are commented, uncomment the JAVA_OPTS and insert the following line between double qoutes.
"JAVA_OPTS = -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

-Xdebug: tells the VM to start in debugging mode.
-Xrunjdwp: selects the protocol to use,address: the port,suspend=n: tells the server to start listening even if no debugger is connected, simply, start and dont wait for a debugger to connect.

That's it, tomcat is waiting for a debugger to connect.


Mohamed Reda said...

very intersting , but
i can`t imagine what will happen after establishing connection ?
can i inspect variables, and know runtime values ?
n.b) the application server don`t have source code

Youssef Mamdouh said...

the source code is on your machine, the application server has the .Class files of The application. The application under debugging should be compiled with debugging enabled so lines numbers could be tracked. A remote debugger just asks the server for information to track the execution of the application.