Sie sind auf Seite 1von 12

Tomcat Debugging

Aaron Zeckoski
azeckoski@gmail.com
Creative Commons AttributionNonCommercial-ShareAlike 2.5 License

Sakai Programmer's Caf

Why bother with a debugger?


Allows tracing of unfamiliar code
Learning process

Reduces the busywork involved with


adding in lots of logging
System.out.println
Log.debug

Allows ability to see what is going on in


code outside your control
2

Programmers Cafe
Instructions for setting up tomcat
debugging are available on the caf
website
http://bugs.sakaiproject.org/confluence/display/BOOT/

Tomcat JPDA
Java Platform Debugger Architecture
Tomcat can be configured to allow a
program such as eclipse to connect
remotely and see debugging information
Simply need to add a command line option
jpda start (possibly debug in older versions)
WIN:

set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
bin/catalina.bat jpda start

UNIX: export JPDA_ADDRESS=8000


export JPDA_TRANSPORT=dt_socket
bin/catalina.sh jpda start
URL: http://confluence.sakaiproject.org/confluence/x/_KM

Adjusting the tomcat startup script


This is an easy way to always have your
server listening for a debugger connection
Add the following environment variables at the
beginning of your startup script
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket

Adjust the startup line at the end of the script


WIN: call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
UNIX: exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"
5

Configuring eclipse

Eclipse can be configured to provide


debugging information for a running
tomcat instance that is configured with
JPDA support
You will need to have tomcat setup first

URL: http://confluence.sakaiproject.org/confluence/x/-qM

Setup Eclipse Tomcat Debugging


Under the "Run" menu, select "Debug"
Double-click the heading "Remote Java Application to
create a new configuration
Enter a meaningful name for this configuration
(e.g. sakai_tomcat_debug)

Change to the "Source" tab, then click "Add"


Click "Java Project", then click "OK"
Click "Select All, then click "OK"
(or check the projects you wish to import)

Click the "Connect" tab and check the box marked "Allow
termination of remote JVM"
Click "Apply" to save your changes
7

Using Eclipse to Debug Sakai


Set a breakpoint somewhere in your code
(preferably something not associated with
startup) by left-clicking to the left of a line of
code
Click on the debug icon at the top (looks like a
little bug) to start debugging
Might need to click the down arrow and select your
sakai debugging config

Click through the app in a browser until your


breakpoint is reached
Focus will shift to the debugger automatically
8

Eclipse Debugging
Lots of tutorials available online
Use google search!

In a nutshell
create breakpoints
Use the step-into, step-over, etc to navigate
through the code
Use Resume to start running code again
Disconnect to break the debug connection
Stop to shutdown tomcat
9

More tomcat stuff


Can redeploy your sakai apps in tomcat
Just run maven sakai from within the tool
directory of most any sakai app project

Cannot redeploy the services though


If you run maven sakai from within the
service directory or with the root of a project
while tomcat is running then Sakai will die
horribly
Just restart tomcat and everything will be ok
again
10

Windows Webapp redeployment


Windows locks the files and jars in tomcat so
that it is difficult to redeploy webapps
Overcome this limitation by adding the
antiResourceLocking and antiJARLocking
attributes to your base context file context.xml
($CATALINA_HOME/conf/context.xml)
<!-- The contents of this file will be loaded for each web application -->
<Context antiJARLocking="true" antiResourceLocking="true" >
<!-- Default set of monitored resources -->

URL: http://confluence.sakaiproject.org/confluence/x/-qM

11

Questions?

12

Das könnte Ihnen auch gefallen