Single Webapp Jetty 7 Configuration
When developing a webapp in Java, I prefer to use Jetty when possible. While it’s easy enough to drop an exploded war into the webapps directory, often I want the app hosted at the root without all of the extra options that Jetty includes by default.
With a simple XML configuration, this is pretty straightforward to do. First, get Jetty (I’m using the latest stable of version 7):
$ wget -r -nc -np -nd -A zip "http://download.eclipse.org/jetty/stable-7/dist/" $ unzip jetty-*.zip $ rm jetty-*.zip
Then download this config file to the Jetty directory:
$ cd jetty-* $ wget "https://raw.github.com/gist/1130234/638e7405f901b378bb8daa18ef1d81fabc9023de/jetty-single-webapp.xml"
By default, Jetty will include a number of additional config files. To ignore them, an empty --ini= parameter is required, like so:
$ java -Dwebapp=/path/to/webapp -jar start.jar --ini= jetty-single-webapp.xml
Note the space directly after --ini=
The config file refers to 3 properties: jetty.port, webapp, and webapp.context.
jetty.port: the port to which the HTTP server is bound.webapp: the filesystem path, relative to the Jetty directory, that will be used as the root of the webapp (defaults to “webapp” next to the Jetty directory).webapp.context: the base context path where the webapp will be published (defaults to “/”).
That’s all there is to it. With this it’s easy to host different apps by changing the webapp property or run multiple apps with multiple Jetty instances (on different ports with the jetty.port property), plus Jetty starts up quicker without the extra options.

