Serving Static Content with the Maven Jetty Plugin

I was having an issue recently where I was using the maven jetty plugin to run a set of mock web services. I needed to be able to also host static pages for redirects. Jetty’s documentation is not brilliant, and it took me a while to find the solution. Define a custom ContextHandler…

Insert the following into your pom.xml:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>7.1.0.RC0</version>
  <configuration>
  <contextHandlers>
    <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
      <contextPath>/static</contextPath>
      <resourceBase>src/main/webapp/static</resourceBase>
      </contextHandler>
    </contextHandlers>
  </configuration>
</plugin>

This creates a custom context handler, and redirects all requests to /static to the local folder src/main/webapp/static (this can be any folder on your machine)

One thought on “Serving Static Content with the Maven Jetty Plugin

  1. After so much research, stumbled across this entry, which is *exactly* what I need. Thanks a ton for sharing!

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

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