This tutorial will show how to debug Java code on remote Tomcat process, this steps are tested on Windows XP,JDK 1.5 and Tomcat 4.1, I believe it will work also on Linux and recent version of Tomcat.
It’s actually beneficial to debug your applications on a separate Tomcat instance instead of the Tomcat built in Netbeans, this especially important in complex and large Java projects to help reduce complexities. Generally you can remotely debug from any Java IDE into any remote servlet server process, in this tutorial I am just showing how to do it between Netbeans and Tomcat.
First, the Tomcat process must run in debug mode, this means you can’t use the backgroud service in Windows, you have to use batch files.
You can use this command line to start Tomcat in debug mode: (after adjusting folders directories)
C:jdk1.5.0_02binjava.exe -jar -Xdebug -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7001 -Duser.dir=”C:Tomcat4.1″ -Djava.endorsed.dirs=”C:Tomcat4.1commonendorsed” “C:Tomcat4.1binbootstrap.jar” start
As I said it is a ommand line, so it’s all one line.
You can also run Tmcat in debug mode using the batch files already distributed with Tomcat.
- Under Tomcatbin make a copy from “startup.bat” and name it “startup_debug.bat”
- Make copy from “catalina.bat” amd rename it to be “catalina_debug.bat”.
- modify “startup_debug.bat”, make it call “catalina_debug.bat” instead of “catalina.bat”.
- Modify “catalina_debug.bat” by adding -Xdebug switch:
CATALINA_OPTS=%CATALINA_OPTS% -Xdebug -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7001
- Saved it and you have finished.
Now its the step of attaching to Tomcat from Netbeans,
in Netbeans:
Run the followng menu commans:
Debug -> Start Session -> Attach -> Connector: Socket Attach -> Host:
“localhost” and Port: 7001
Set your breakpoints and enjoy it.