Static content with Maven Jetty Plugin

Cemo picture Cemo · Feb 21, 2011 · Viewed 8k times · Source

How can I serve static content with maven jetty plugin (7.x)

Thanks

Answer

Nishant picture Nishant · Feb 21, 2011

put your static contents under any folder below /yourStaticApp/src/main/webapp -- say under /yourStaticApp/src/main/webapp/static. When you will run Jetty these will be available as http://host:port/contextRoot/static/fileName.ext


Hmmm, unsure, if that's possible. Eclipse Jetty Maven plugin documents a way to configure static source location, which boils down to the alternate location of webapps mentioned above.

 ...
 <plugin>
    ...
    <configuration>
      <webAppSourceDirectory>${basedir}/src/staticfiles</webAppSourceDirectory>
      ...
    </configuration>
    ...
  </plugin>
  ...

As the doc points out:

<webAppSourceDirectory>–By default, this is set to ${basedir}/src/main/webapp. If your static sources are in a different location, set this parameter accordingly.

refer: http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin


Update: On some more reseach I found out that you can actually point the location of webdefault.xml from in Jetty-maven plugin; and in webdefault.xml you can configure the static content location.

In your Jetty Maven configuration, point the location of wendefault.xml

  <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <configuration>
     ...
      <defaultsDescriptor>/my/path/to/webdefault.xml</defaultsDescriptor>
     ...
    </configuration>
  </plugin>

Now, with webdefault.xml in your hand you can put the configuration mentioned here: http://docs.codehaus.org/display/JETTY/Static+Content -- except the package Names has been changed from org.mortbay.jetty... to org.eclipse.jetty... see below:

<Configure class="org.eclipse.jetty.servlet.Context">
  <Set name="contextPath">/javadoc</Set>
  <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc/</Set>
  <Call name="addServlet">
    <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
    <Arg>/</Arg>
  </Call>
</Configure>

refer: http://wiki.eclipse.org/Jetty/Reference/webdefault.xml

I haven't tested/used the above. But let me know, if you get this working. Or if anything else needed to get this done.