Jetty has moved!
Jetty is a project at the Eclipse Foundation.
Homepage:http://www.eclipse.org/jetty
Downloads: http://download.eclipse.org/jetty/
Documentation:http://www.eclipse.org/jetty/documentation/current/
About:http://www.eclipse.org/jetty/about.php
Jetty Powered:http://www.eclipse.org/jetty/powered/
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Skip to end of metadata
Go to start of metadata

Debugging with the Maven Jetty Plugin in Eclipse

Step 1
Go to the Run/External Tools/External Tools ..." menu item on the "Run" menu bar. Select "Program" and click the "New" button. On the "Main" tab, fill in the "Location:" as the full path to your "mvn" executable. For the "Working Directory:" select the workspace that matches your webapp. For "Arguments:" add jetty:run.

Move to the "Environment" tab and click the "New" button to add a new variable named MAVEN_OPTS with the value:

-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y

If you supply suspend=n instead of suspend=y you can start immediately without running the debugger and launch the debugger at anytime you really wish to debug.

Step 2

Then, pull up the "Run/Debug/Debug ..." menu item and select "Remote Java Application" and click the "New" button. Fill in the dialog by selecting your webapp project for the "Project:" field, and ensure you are using the same port number as you specified in the address= property above.

Now all you need to do is to Run/External Tools and select the name of the maven tool setup you created in step 1 to start the plugin and then Run/Debug and select the name of the debug setup you setup in step2.

From instructions provided by Rolf Strijdhorst on the Maven mailing list

Stopping Jetty

In order to stop the jetty server the "Allow termination of remote VM" should be checked in debug dialog in Step 2. When you have the jetty server running and the debugger connected you can switch to the debug perspective. In the debug view, right click on the Java HotSpot(TM) Client VM[localhost:4000] and  chose terminate. This will stop the debugger and the jetty server.

7 Comments

  1. Here one other method to debug web application based on jetty and maven2 : http://mahertb.blogspot.com/2006/08/debugging-maven-web-application-with.html

  2. Good day,

    Great tutorial ! (smile) 

    I would just like to add that that is actually the generic way of debugging Maven2 in Eclipse. It works not only with jetty:run, but practically anything that does not fork another JVM (i.e. maven-surefire-plugin). Kindly see [1] for more info.

    Cheers,
    Franz 

    [1] http://docs.codehaus.org/display/MAVENUSER/Dealing+with+Eclipse-based+IDE

  3. I do not think that steps here do anything useful. They will allow to debug Maven (and maybe unit tests), but not Jetty or code running in Jetty. Jetty forks a new JVM. Parameters specified will apply to maven process, but not to the forked JVM... Not sure why other comments say that it's a great tutorial considering that it just does not work...

    Unfortunately I am not sure yet how to config Jetty so that it would be possible to debug... 

  4. These steps works. I tested it and all was as expected. The breakpoints in my webapp where enabled and worked.

    Thank you for your help. 

  5. Works brilliantly.
    But how do you stop the jetty server without using the terminate button and leaving the java process hanging in nowhere?

  6. I've also encountered that problem. I think this is due to this bug.

  7. Thanks (wink) the method works.

    but i can not find the method to stop the jetty.

    Is there some method ? thanks again !!!

Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery