Wednesday, February 18, 2009

Debugging Jetty when running mvn jetty:run

It took me awhile to get this to work so hopefully this will save someone some time. If you want to debug a webapp that is run using the mvn jetty:run or mvn jetty:run-war commands then these steps will help you get going quickly.
1) setup your webapp to run using jetty: Maven Jetty Plugin Guide
2) setup the debugger in one of the following ways:
(A) setup your MAVEN_OPTS (environment variable) to include debugging by adding this "-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n".
Mine looks like this: MAVEN_OPTS='-Xms256m -Xmx512m -XX:PermSize=64m -XX:MaxPermSize=128m -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n'
If you want it to suspend until the debugger is attached then just set suspend=y
Note that this will stop you from running more than one mvn process
(B) execute mvn using the mvndebug script (skip step 3)
mvndebug jetty:run
The only issue with this is that it suspends always and you cannot kill it without attaching to it with a debugger (this annoys me so I use the first option)
Note that you can only have one mvndebug process running at once
3) Execute mvn jetty:run
4) Attach a debugger (like the one in eclipse) to port 8000 and you are ready to debug