Christopher G Johnson: programmer, entrepreneur, father

Configuring Jetty, Maven, and Eclipse together with Hot Swap

with 10 comments

For over a year I’ve been developing a Java webapp in Hibernate with maven and Jetty.  Recently I’ve figure out how to make them all play nice with each other.  For too long I had to restart my application server, which takes upwards of 45 seconds, for any code changes to make it to my development server.  This tutorial will show you how to setup Jetty in embedded mode, and using Eclipse, attach a debugger to enable True Hot Swap of code onto your Jetty server.

Environment Information:

JDK 1.5+
Eclipse 3.4.0
maven 2.0.10
m2eclipse 0.9.7 (maven plugin for eclipse)
Jetty 6.1.10

Maven Jetty Configuration:

In your maven project’s pomx.xml, in your <build> section, add the jetty plugin.  An example can be found at the Jetty website here:

It is very important to keep <scanIntervalSeconds> set to zero.  This setting tells Jetty how often (in seconds) to scan the webapp for changes and if changes are found, it re-cycles the web container.  You don’t want to do this and setting it to zero will disable it.

Configuring Jetty to start within Eclipse:

Next, create an easy way to launch your jetty server.  I’m using Jetty through Maven and Eclipse.  Here is how I setup an Eclipse External Tool to launch my Jetty server:

To make sure it is listening for a debugger, make sure that a MAVEN_OPTS environment variable is set with the following options:

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

The address parameter is what port the jetty server will be listening on for the remote debugger.

Click ‘Run’ and your jetty server should start running in Eclipse’s console window.  It should look something like this (depending on your log4j config):

Listening for transport dt_socket at address: 4000

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'jetty'.
[INFO] ------------------------------------------------------------------------
[INFO] Building myProject
[INFO]    task-segment: [jetty:run]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing jetty:run
2010-05-27 15:39:25.733::INFO:  Started SelectChannelConnector@
[INFO] Started Jetty Server

Attaching the Debugger:

Next, setup a debugger.  In Eclipse open ‘Debug Configurations’, and create a new ‘Remote Java Debugger’.   Select your eclipse project, set the host to localhost, and set the port to 4000, or whatever you defined earlier.

Press the Debug Button and the remote debugger should attach to your jetty server.

Finally, make sure Build Automatically is enabled in eclipse (Project->Build Automatically).

At this point your environment is enabled for debugging code on your Jetty server through Eclipse.  Breakpoints, watch variables, you name it.

Hot deploy is also enabled.  If you modify some java code, the automatic builder should compile the .java file to a .class file.  The remote debugger will see it and use it, all without restarting your jetty server or its web container.  This will not work for things like adding static variables, new domain classes, or new injectable service methods that require the application to acknowledge them on startup.



Still reading?  Check out my latest project : where you can find your favorite craft beers or microbrews near you.

Written by clickonchris

May 27th, 2010 at 11:06 pm

Posted in Databases,Java,Programming

Tagged with

10 Responses to 'Configuring Jetty, Maven, and Eclipse together with Hot Swap'

Subscribe to comments with RSS or TrackBack to 'Configuring Jetty, Maven, and Eclipse together with Hot Swap'.

  1. Hi, really helped me.

    Gaurav Gupta

    19 Sep 11 at 10:46 pm

  2. it do not work when i change code in a spring controller class with @Controller annotation.can you tell me the reason.


    18 May 12 at 2:31 am

  3. Rex, I think it should work as long as you’re not actually modifying the annotation (in that case you would need to restart)


    11 Sep 12 at 7:34 pm

  4. Thanks a ton.
    It helped where I struggled.
    This is the easiest way available as compared to other resources on the net.


    3 Oct 12 at 8:13 am

  5. I have resolved my problem. My project use maven and aspectJ. I use AJDT and m2e plugin to develop in eclipse. In this case, i install AJDT configurator for m2e v1.0 to let hot-swap work. (
    When i want to share my hot-swap experience, i check this page again. i’m glad to see your reply. Thanks for your reply.


    14 Oct 12 at 9:45 pm

  6. Thanks it really worked!!


    26 Jun 13 at 8:21 am

  7. I found RunJettyRun plugin, worked well:

    Scott Rosenbaum

    7 Jan 15 at 5:29 pm

  8. Interesting article. You should use social websites to increase traffic and make
    your site go viral. There are tools which automate this time consuming process.Visitors can flood your website in no time,
    just type in google for:
    Rixisosa’s Social Automation


    1 Mar 15 at 4:36 am

  9. Thanks, nice tips

    Binh Thanh Nguyen

    31 Aug 16 at 12:35 am

  10. I was very usefull. I tried several ways and this worked perfect


    2 Sep 16 at 8:11 am

Leave a Reply

Switch to our mobile site