Version: 9.4.32.v20200930 |

webdefault.xml
Previous | Chapter 32. Jetty XML Reference Home | Next

##### Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development

## webdefault.xml

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, the `$JETTY-HOME/etc/jetty-deploy.xml` file will configure jetty to automatically use `$JETTY_HOME/etc/webdefault.xml`.

> ### Note

> To ensure your `webdefault.xml` files are validated, you will need to set the `validateXml` attribute to true as described here.

The `webdefault.xml` included with the Jetty Distribution contains several configuration options, such as init params and servlet mappings, and is separated into sections for easy navigation. Some of the more common options include, but are not limited to:

dirAllowed
  If true, directory listings are returned if no welcome file is found. Otherwise 403 Forbidden displays.
precompressed
  If set to a comma separated list of file extensions, these indicate compressed formats that are known to map to a MIME-type that may be listed in a requests Accept-Encoding header. If set to a boolean True, then a default set of compressed formats will be used, otherwise no pre-compressed formats.
maxCacheSize
  Maximum total size of the cache or 0 for no cache.
maxCachedFileSize
  Maximum size of a file to cache.
maxCachedFiles
  Maximum number of files to cache.

#### 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.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>
      ...
    </Configure>

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.
        wac.setDefaultsDescriptor("/my/path/to/webdefault.xml");
        ...

Alternatively, you can use a Jetty Classloading 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 in the `$JETTY_HOME/etc/jetty-deploy.xml` file:

       <Set name="defaultsDescriptor"><Property name="jetty.home" default="." />/other/path/to/another/webdefault.xml</Set>

#### Using the Jetty Maven Plugin

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

    <project>
        ...
        <plugins>
            <plugin>
                ...
                <artifactId>jetty-maven-plugin</artifactId>
                <configuration>
                    <webApp>
                      ...
                      <defaultsDescriptor>/my/path/to/webdefault.xml</defaultsDescriptor>
                    </webApp>
                </configuration>
            </plugin>
            ...
        </plugins>
        ...
    </project>

#### Additional Resources

- jetty-web.xml –Reference for `web.xml` files
- Jetty override-web.xml –Information for this `web.xml` -formatted file, applied after the webapp’s `web.xml` webapp.
- jetty.xml –Reference for `jetty.xml` files

Previous | Top | Next
jetty-env.xml | Home | Jetty override-web.xml

See an error or something missing? Contribute to this documentation at Github!(Generated: 2020-09-30)