Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

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

m
Line 6: Line 6:
 
| body =  
 
| body =  
  
== Using <tt>webdefault.xml</tt> / Providing a Custom <tt>webdefault.xml</tt> ==
+
== Using <tt>webdefault.xml</tt> ==
  
=== Using <tt>webdefault.xml</tt> ===
+
You can find <tt>webdefault.xml</tt> in <tt>$JETTY_HOME/etc/webdefault.xml</tt>. You can specify another configuration file to use for specific webapps, or for all webapps. If you do not specify an alternate defaults descriptor,  <tt>webdefault.xml</tt> is automatically used.
  
The distribution's <tt>webdefault.xml</tt> can be found at <tt>$JETTY_HOME/etc/webdefault.xml</tt>. 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 <tt>webdefault.xml</tt> will automatically be used.
+
=== Creating a Custom <tt>webdefault.xml</tt> for One WebApp ===
 
+
=== Jetty Standalone ===
+
 
+
==== Custom <tt>webdefault.xml</tt> for One Webapp ====
+
 
You can specify a custom <tt>webdefault.xml</tt> for an individual web application in that webapp's [[Jetty/Reference/jetty-web.xml|jetty-web.xml]].  
 
You can specify a custom <tt>webdefault.xml</tt> for an individual web application in that webapp's [[Jetty/Reference/jetty-web.xml|jetty-web.xml]].  
  
Line 41: Line 37:
 
Alternatively, you can use a classloader to find the resource representing your custom <tt>webdefault.xml</tt>.
 
Alternatively, you can use a classloader to find the resource representing your custom <tt>webdefault.xml</tt>.
  
==== Custom <tt>webdefault.xml</tt> for Multiple Webapps ====
+
=== Custom <tt>webdefault.xml</tt> 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 <tt>[[Jetty/Reference/jetty.xml|jetty.xml]]</tt>.
+
If you want to apply the same custom webdefault.xml to a number of webapps, provide the path to the file in <tt>[[Jetty/Reference/jetty.xml|jetty.xml]]</tt> either to the hot deployer (Context Deployer) or the static deployer (WebAppDeployer). For example:
  
 
<source lang="xml">
 
<source lang="xml">
Line 57: Line 53:
 
=== Jetty Maven Plugin ===
 
=== Jetty Maven Plugin ===
  
Similarly, for the [[Jetty/Feature/Jetty Maven Plugin|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 as follows:
 
<source lang="xml">
 
<source lang="xml">
 
<project>
 
<project>

Revision as of 14:40, 19 August 2010



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

You can find webdefault.xml in $JETTY_HOME/etc/webdefault.xml. You can specify another configuration file to use for specific webapps, or for all webapps. If you do not specify an alternate defaults descriptor, webdefault.xml is automatically used.

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.

<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, provide the path to the file in jetty.xml either to the hot deployer (Context Deployer) or the static deployer (WebAppDeployer). 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>
    </New>
    ...
</Configure>

Jetty Maven Plugin

Similarly, for 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>
                <webAppConfig>
                  ...
                  <defaultsDescriptor>/my/path/to/webdefault.xml</defaultsDescriptor>
                </webAppConfig>
            </configuration>
        </plugin>
        ...
    </plugins>
    ...
</project>

Additional Resources

Back to the top