Wednesday, November 09, 2005

SOAP : Debugging Axis with Tomcat and Eclipse

Using Tomcat 5.0 and Eclipse 3.1.

In your Tomcat/bin directory, there is a file called catalina.bat. From the command prompt, just run catalina to see the options. You'll see one option called:

jpda start Start Catalina under JPDA debugger

That's the one you need. I had endless problems running this until I changed the relevant part of the bat file to:

%_EXECJAVA% -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %ACTION%

i.e. the address and transport are specified in the command line rather than in environment options.

Now start Tomcat with this option.

In Eclipse, the project is set up in the normal way with java classes etc.

Breakpoint where you want the code to stop inside Tomcat (e.g. inside a web service)
and then select Run / Debug / Remote Java Application.

You only need to worry about the Connect tab. "Connection Type" is "Standard (Socket Attach)", host is e.g. "localhost" and the port is the port specified in the command line above under the "address" option i.e. 8000. Then press the "Debug" button.

Now invoke whatever to force your Tomcat code to execute e.g. running a web service client which invokes the web service you want to debug.

Bingo - Eclipse will catch the breakpoint and change to the Debug perspective.

Enjoy!

No comments: