Difference between revisions of "Jetty/Reference/webdefault.xml"

From Eclipsepedia

Jump to: navigation, search
Line 57: Line 57:
 
=== Jetty Maven Plugin ===
 
=== Jetty Maven Plugin ===
  
Similarly, for the [[Jetty/Feature/Jetty Maven Plugin]], you provide a customized webdefault.xml file for your webapp by:
+
Similarly, for the [[Jetty/Feature/Jetty Maven Plugin|Jetty Maven Plugin]], you provide a customized webdefault.xml file for your webapp by:
 
<source lang="xml">
 
<source lang="xml">
 
<project>
 
<project>

Revision as of 05:17, 10 August 2009



Contents

Introduction

webdefault.xml is a file which is applied to a web application before the application's own WEB-INF/web.xml. It is used to save a web application from having to define a lot of house-keeping and container-specific elements in their own web.xml files, and uses the web.xml syntax. For example, you can use it to set up mime-type mappings and JSP servlet-mappings. 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.

Your Jetty distribution's webdefault.xml file can be found in $(jetty.home)/etc/webdefault.xml.

Using webdefault.xml / Providing a Custom webdefault.xml

Using webdefault.xml

The distribution's webdefault.xml can be found at $JETTY_HOME/etc/webdefault.xml. You may specify another configuration file to be used for specific webapps, or for all webapps (see below). If you do not specify an alternate defaults descriptor, the distribution's webdefault.xml will automatically be used.

Jetty Standalone

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.

<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 classloader to find the resource representing your custom webdefault.xml.

Custom webdefault.xml for Multiple Webapps

If you want to apply the same custom webdefault.xml to a number of webapps, then supply the path to the file to the hot deployer (ContextDeployer) or the static deployer (WebAppDeployer) in your jetty.xml.

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

Jetty Maven Plugin

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

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

Additional Resources