Convenience wrapper for setting up an embedded Jetty server with Guice Filter
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Build Status Download

This library makes it easy to set up an embedded Jetty server using Guice Servlet's GuiceFilter. It also provides sane defaults for TLS, makes it easy to serve static files, and integrates logback-access. This doesn't let you do anything that Jetty's API doesn't already let you do; it just hides some boilerplate.

Artifacts are released in Bintray. For gradle, use the jcenter() repository. For maven, go here and click "Set me up".


A simple HTTP server with a servlet:

// set up Guice injector
Injector injector = Guice.createInjector(new AbstractModule() {
        protected void configure() {
            // module for this library
            install(new HttpServerWrapperModule());
            // servlet module to bind servlets to paths
            install(new ServletModule() {
                protected void configureServlets() {

// serve static files like /static/foo.jpg
HttpResourceHandlerConfig rhConfig = new HttpResourceHandlerConfig()

HttpServerWrapperConfig config = new HttpServerWrapperConfig()
            .withHttpServerConnectorConfig(HttpServerConnectorConfig.forHttp("localhost", 8080));

// you now have a server listening on localhost:8080

Requests that do not match any configured pattern for GuiceFilter (in this case, the /somewhere pattern configured in the ServletModule) will 404.

What's In The Box

There are a few main classes you'll interact with.


This class represents one individual connector. A server can have many connectors listening on different ports and with or without TLS.

To make a connector for plain HTTP:

HttpServerConnectorConfig.forHttp("localhost", 8080)

For a plain HTTP connector, there's nothing further to configure.

For a HTTP+TLS connector, you must specify a keystore and passphrase.

HttpServerConnectorConfig.forHttps("localhost", 8443)

You can use fluent-style .with* methods that return the current config object after modification, or plain old setters.

You may also specify the TLS cipher suites and TLS protocols to use, but the defaults are sane, so typically you can just leave them alone.


This class represents config that is scoped at the server level, not the connector level.

For basic usage all you need to do is add a connector:

HttpServerWrapperConfig config = new HttpServerWrapperConfig()
            .withHttpServerConnectorConfig(HttpServerConnectorConfig.forHttp("localhost", 8080));

The default config generates access logs on stdout via Logback Access. You can specify a logback-access config file on the classpath:


or on the filesystem:


You can also set the max form content size that Jetty will allow:


Like HttpServerConnectorConfig, you can use .with* methods or .set* methods to set parameters.


Used for serving static files. See the Javadoc or source for all available config options.

HttpResourceHandlerConfig rhConfig = new HttpResourceHandlerConfig()
    .withWelcomeFiles(Lists.newArrayList("almost-like-index.html", "another-one.html"));

HttpServerWrapperConfig config = new HttpServerWrapperConfig()


This is what you inject into your own code to use with a HttpServerWrapperConfig to create a HttpServerWrapper.


When you get a HttpServerWrapper instance from a HttpServerWrapperFactory, it contains a configured but not yet started Jetty server.

When you want to start the server, call start(). When you want to stop it, call stop(). Crazy, right?