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/override-web.xml"

Line 1: Line 1:
 
{{Jetty Reference
 
{{Jetty Reference
| introduction = <tt>override-web.xml</tt> is a file which is applied to a web application ''after'' the application's own WEB-INF/web.xml. It is defined per-webapp, and uses the [[web.xml Syntax|web.xml syntax]].
+
| introduction = <tt>override-web.xml</tt> is a file which is applied to a web application ''after'' the application's own WEB-INF/web.xml. It is defined per-webapp, and uses the [[Jetty/Reference/web.xml Syntax|web.xml syntax]].
  
 
A common need is to be able to deploy the same ''unchanged'' webapp or WAR into different environments, while being able to customize the webapp for that environment. You can change the configuration using a <tt>[[Jetty/References/jetty.xml|jetty.xml]]</tt> file, to some extent, as <tt>jetty.xml</tt> does not form part of the webapp. It therefore can be changed per deployment. However, there are some things you might want to change that <tt>jetty.xml</tt> cannot help you with: for example, servlet init-params and context init-params. Using <tt>[[Jetty/References/webdefault.xml|webdefault.xml]]</tt> won't help you either, because it is applied first, and so cannot override values inside the webapp's <tt>web.xml</tt>.
 
A common need is to be able to deploy the same ''unchanged'' webapp or WAR into different environments, while being able to customize the webapp for that environment. You can change the configuration using a <tt>[[Jetty/References/jetty.xml|jetty.xml]]</tt> file, to some extent, as <tt>jetty.xml</tt> does not form part of the webapp. It therefore can be changed per deployment. However, there are some things you might want to change that <tt>jetty.xml</tt> cannot help you with: for example, servlet init-params and context init-params. Using <tt>[[Jetty/References/webdefault.xml|webdefault.xml]]</tt> won't help you either, because it is applied first, and so cannot override values inside the webapp's <tt>web.xml</tt>.

Revision as of 02:01, 29 June 2009



Introduction

override-web.xml is a file which is applied to a web application after the application's own WEB-INF/web.xml. It is defined per-webapp, and uses the web.xml syntax.

A common need is to be able to deploy the same unchanged webapp or WAR into different environments, while being able to customize the webapp for that environment. You can change the configuration using a jetty.xml file, to some extent, as jetty.xml does not form part of the webapp. It therefore can be changed per deployment. However, there are some things you might want to change that jetty.xml cannot help you with: for example, servlet init-params and context init-params. Using webdefault.xml won't help you either, because it is applied first, and so cannot override values inside the webapp's web.xml.

The solution is to use an override web.xml file. This is another whole or partial web.xml file that resides externally to the webapp. It is applied after the webapp's WEB-INF/web.xml file and can therefore override or add new elements.

Using override-web.xml

Jetty Standalone

You can specify the override-web.xml to be used for an individual web application, in that webapp's jetty-web.xml.

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  ...
  <!-- Set up the path to the custom override descriptor, 
  relative to your $(jetty.home) directory or to the current directory -->
  <Set name="overrideDescriptor"><SystemProperty name="jetty.home" default="."/>/my/path/to/override-web.xml</Set>
  ...
</Configure>

In code, this is:

import org.eclipse.jetty.webapp.WebAppContext;
 
    ...
 
    WebAppContext wac = new WebAppContext();
    ...
    //Set the path to the override descriptor, based on your $(jetty.home) directory
    wac.setOverrideDescriptor(System.getProperty("jetty.home")+"/my/path/to/override-web.xml");
    ...

Alternatively, use the classloader to get the path to the override descriptor as a resource.

Jetty Maven Plugin

Use the <overrideDescriptor> tag as follows:

<project>
    ...
    <plugins>
        <plugin>
            ...
            <artifactId>jetty-maven-plugin</artifactId>
            <configuration>
                <webAppConfig>
                  ...
                  <overrideDescriptor>src/main/resources/override-web.xml</overrideDescriptor>
                </webAppConfig>
            </configuration>
        </plugin>
        ...
    </plugins>
    ...
</project>

Additional Resources

Copyright © Eclipse Foundation, Inc. All Rights Reserved.