Skip to main content
Jump to: navigation, search


< Jetty‎ | Reference
Revision as of 15:43, 23 April 2013 by (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Jetty 7 and Jetty 8 are now EOL (End of Life)

All development and stable releases are being performed with Jetty 9.
This wiki is now officially out of date and all content has been moved to the Jetty Documentation Hub

Direct Link to updated documentation:

The webdefault.xml file saves web applications from having to define a lot of house-keeping and container-specific elements in their own web.xml files. For example, you can use it to set up mime-type mappings and JSP servlet-mappings. Jetty applies webdefault.xml to a web application before the application's own WEB-INF/web.xml, which means that it cannot override values inside the webapp's web.xml. It uses the jetty.xml syntax. Generally, it is convenient for all webapps in a Jetty instance to share the same webdefault.xml file. However, it is certainly possible to provide differentiated webdefault.xml files for individual web applications.

The webdefault.xml file is located in $(jetty.home)/etc/webdefault.xml.

Using webdefault.xml

You can specify a custom configuration file to use for specific webapps, or for all webapps. If you do not specify an alternate defaults descriptor, Jetty automatically uses webdefault.xml.

Creating a Custom webdefault.xml for One WebApp

You can specify a custom webdefault.xml for an individual web application in that webapp's jetty-web.xml as follows:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <!-- Set up the absolute path to the custom webdefault.xml -->
  <Set name="defaultsDescriptor">/my/path/to/webdefault.xml</Set>

The equivalent in code is:

import org.eclipse.jetty.webapp.WebAppContext;
    WebAppContext wac = new WebAppContext();
    //Set up the absolute path to the custom webdefault.xml.

Alternatively, you can use a classloader to find the resource representing your custom webdefault.xml.

Creating a Custom webdefault.xml for Multiple WebApps

If you want to apply the same custom webdefault.xml to a number of webapps, provide the path to the file in jetty.xml either to the hot deployer (Context Provider) or the static deployer (WebAppProvider). For example:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <New class="org.eclipse.jetty.deploy.WebAppDeployer">
        <Set name="defaultsDescriptor">/my/path/to/webdefault.xml</Set>

Using the Jetty Maven Plugin

Similarly, for the Jetty Maven Plugin, you provide a customized webdefault.xml file for your webapp as follows:


Additional Resources

Back to the top