Embedding Jetty 6 in Spring

There’s not much info out there on embedding a Jetty server in Spring, and much of what does exist is for Jetty 5 (not Jetty 6) or uses helper classes that nobody wants to write. However, there is a decent example hidden in the Jetty Subversion repository (which requires an exploded WAR directory structure), and the Jetty documentation is pretty nice. The API docs are useful, as well.

I had two goals: embed Jetty 6 (not 5), and do so without having to rearrange my directories into an exploded WAR structure. After a bit of tinkering, this is the file I ended up with. It contains 5 servlets and their mappings, just so that you can get a feel for the file, but you can certainly use it with any number of servlets.

Note that I had to change the file extension from .xml to .txt in order to appease my blogging software… Note also that this setup does not require the exploded WAR directory structure. The parts you’ll probably want to customize are the servlets list, the servletMappings list, the resourceBase property, and possibly the contextPath property.

Advertisement

5 Comments

  1. dude said,

    May 9, 2008 at 10:37 pm

    Awesome man… thanks!

  2. Jan said,

    July 28, 2008 at 4:48 pm

    based on your work (but with much more convinient web.xml)

  3. Moritz Both said,

    December 28, 2009 at 5:43 am

    Thanks for the file. Can I use this as a base in any way freely in a commercial projekt?

    Thanks
    Moritz

  4. Daniel Gredler said,

    December 28, 2009 at 10:36 pm

    @Moritz: Yeah, no problem. There’s not much to it; consider it public domain.

  5. d1ve2blu3 said,

    December 6, 2011 at 5:01 am

    hi, I had problem accessing your file

    — 403: Access Denied —

    This file requires authorization:

    You must both be a user of this blog as well as be currently logged into

    thanks


Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.