Skip to main content
summaryrefslogtreecommitdiffstats
blob: e27050637aaed3f8cca6710b327db8ebfed005dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Deployment Processing of WebAppContexts</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="configuring-deployment.html" title="Chapter&nbsp;4.&nbsp;Deploying to Jetty"><link rel="prev" href="configuring-specific-webapp-deployment.html" title="Configuring a Specific Web Application Deployment"><link rel="next" href="static-content-deployment.html" title="Configuring Static Content Deployment"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script>
      hljs.initHighlightingOnLoad();
    </script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
            Version: 9.4.0-SNAPSHOT</span></td><td style="width: 50%"><script type="text/javascript">  (function() {
            var cx = '016459005284625897022:obd4lsai2ds';
            var gcse = document.createElement('script');
            gcse.type = 'text/javascript';
            gcse.async = true;
            gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
            '//www.google.com/cse/cse.js?cx=' + cx;
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(gcse, s);
            })();
          </script><gcse:search></gcse:search></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Deployment Processing of WebAppContexts</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="configuring-specific-webapp-deployment.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;4.&nbsp;Deploying to Jetty<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="static-content-deployment.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at
          <span class="website">www.webtide.com</span></a></h5><p>
 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
      </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="configuring-webapps"></a>Deployment Processing of WebAppContexts</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="configuring-webapps.html#webapp-configurations">Configuration Classes</a></span></dt><dt><span class="section"><a href="configuring-webapps.html#webapp-context-attributes">Other Configuration</a></span></dt></dl></div><p>Web applications require a certain amount of processing before they can go into service: they may need to be unpacked, a special classloader created for their jar files, <code class="literal">web.xml</code> and <code class="literal">web-fragment.xml</code> descriptors processed, and classes scanned for annotations amongst other things.
As web applications have become more complex, Jetty has added ways to assist with customization by either broadening or lessening the amount of processing that is done at deployment time.
This section will examine this processing and it can be tailored to fit individual needs.</p><p>If instead you&#8217;re looking for information on how to configure a specific <code class="literal">WebAppContext</code> - such as its context path, whether it should be unpacked or not - then you can find that in the section entitled <a class="link" href="configuring-specific-webapp-deployment.html" title="Configuring a Specific Web Application Deployment">Configuring a Specific WebApp Deployment</a>.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="webapp-configurations"></a>Configuration Classes</h3></div></div></div><p>As a webapp is being deployed, a series of <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/Configuration.html" target="_top">org.eclipse.jetty.webapp.Configuration</a> classes are applied to it, each one performing a specific function.
The ordering of these Configurations is significant as subsequent Configurations tend to build on information extracted or setup in foregoing Configurations.
These are the default list, in order, of Configurations that are applied to each <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/WebAppContext.html" target="_top">org.eclipse.jetty.webapp.WebAppContex</a>t:</p><div class="table"><a name="d0e2802"></a><p class="title"><b>Table&nbsp;4.1.&nbsp;Default Configuration classes</b></p><div class="table-contents"><table class="table" summary="Default Configuration classes" border="1"><colgroup><col class="col_1"><col class="col_2"></colgroup><tbody><tr><td align="left" valign="top"><p><a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/WebInfConfiguration.html" target="_top">org.eclipse.jetty.webapp.WebInfConfiguration</a></p></td><td align="left" valign="top"><p>Extracts war, orders jars and defines classpath</p></td></tr><tr><td align="left" valign="top"><p><a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/WebXmlConfiguration.html" target="_top">org.eclipse.jetty.webapp.WebXmlConfiguration</a></p></td><td align="left" valign="top"><p>Processes a WEB-INF/web.xml file</p></td></tr><tr><td align="left" valign="top"><p><a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/MetaInfConfiguration.html" target="_top">org.eclipse.jetty.webapp.MetaInfConfiguration</a></p></td><td align="left" valign="top"><p>Looks in container and webapp jars for META-INF/resources and
META-INF/web-fragment.xml</p></td></tr><tr><td align="left" valign="top"><p><a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/FragmentConfiguration.html" target="_top">org.eclipse.jetty.webapp.FragmentConfiguration</a></p></td><td align="left" valign="top"><p>Processes all discovered META-INF/web-fragment.xml files</p></td></tr><tr><td align="left" valign="top"><p><a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.html" target="_top">org.eclipse.jetty.webapp.JettyWebXmlConfiguration</a></p></td><td align="left" valign="top"><p>Processes a WEB-INF/jetty-web.xml file</p></td></tr></tbody></table></div></div><br class="table-break"><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_anatomy_of_a_configuration_class"></a>Anatomy of a Configuration Class</h4></div></div></div><p>A Configuration class is called 5 times in different phases of the <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/WebAppContext.html" target="_top"><code class="literal">WebAppContext's</code></a> lifecycle:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">preConfigure</span></dt><dd>As the <code class="literal">WebAppContext</code> is starting up this phase is executed.
The <code class="literal">Configuration</code> should discover any of the resources it will need during the subsequent phases.</dd><dt><span class="term">configure</span></dt><dd>This phase is where the work of the class is done, usually using the resources discovered during the <code class="literal">preConfigure</code> phase.</dd><dt><span class="term">postConfigure</span></dt><dd>This phase allows the <code class="literal">Configuration</code> to clear down any resources that may have been created during the previous 2 phases that are not needed for the lifetime of the <code class="literal">WebAppContext</code>.</dd><dt><span class="term">deconfigure</span></dt><dd>This phase occurs whenever a <code class="literal">WebAppContext</code> is being stopped and allows the Configuration to undo any resources/metadata that it created.
A <code class="literal">WebAppContext</code> should be able to be cleanly start/stopped multiple times without resources being held.</dd><dt><span class="term">destroy</span></dt><dd>This phase is called when a <code class="literal">WebAppContext</code> is actually removed from service.
For example, the war file associated with it is deleted from the $JETTY_HOME/webapps directory.</dd></dl></div><p>Each phase is called on each <code class="literal">Configuration</code> class in the order in which the <code class="literal">Configuration</code> class is listed.
Using the default <code class="literal">Configuration</code> classes as an example, <code class="literal">preConfigure()</code> will be called on <code class="literal">WebInfConfiguration</code>, <code class="literal">WebXmlConfiguration</code>, <code class="literal">MetaInfConfiguration</code>, <code class="literal">FragmentConfiguration</code> and then <code class="literal">JettyWebXmlConfiguration</code>.
The cycle begins again for the <code class="literal">configure()</code> phase and again for the <code class="literal">postConfigure()</code> phases.
The cycle is repeated <span class="emphasis"><em>in reverse order</em></span> for the <code class="literal">deconfigure()</code> and eventually the <code class="literal">destroy()</code> phases.</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_extending_container_support_by_creating_extra_configurations"></a>Extending Container Support by Creating Extra Configurations</h4></div></div></div><p>As shown, there is a default set of Configurations that support basic deployment of a webapp.
JavaEE features such as JNDI and advanced servlet spec features such as annotations have not been mentioned.
Jetty&#8217;s philosophy is to allow the user to tailor the container exactly to their needs.
If these features are not needed, then Jetty does not pay the price for them - an important consideration because features such as annotations require extensive and time-consuming scanning of <code class="literal">WEB-INF/lib</code> jars.
As modern webapps may have scores of these jars, it can be a source of significant deployment delay.
We will see in the section <a class="link" href="configuring-webapps.html#webapp-context-attributes" title="Other Configuration">Other Configuration</a> another helpful webapp facility that Jetty provides for cutting down the time spent analyzing jars.</p><p>Jetty makes use of the flexibility of Configurations to make JNDI and annotation support pluggable.</p><p>Firstly, lets look at how Configurations help enable JNDI.</p><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="jndi-configuration-classes"></a>Example: JNDI Configurations</h5></div></div></div><p>JNDI lookups within web applications require the container to hookup resources defined in the container&#8217;s environment to that of the web application.
To achieve that, we use 2 extra Configurations:</p><div class="table"><a name="d0e2977"></a><p class="title"><b>Table&nbsp;4.2.&nbsp;JNDI Configuration classes</b></p><div class="table-contents"><table class="table" summary="JNDI Configuration classes" border="1"><colgroup><col class="col_1"><col class="col_2"></colgroup><tbody><tr><td align="left" valign="top"><p><a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/plus/webapp/EnvConfiguration.html" target="_top">org.eclipse.jetty.plus.webapp.EnvConfiguration</a></p></td><td align="left" valign="top"><p>Creates <code class="literal">java:comp/env</code> for the webapp, applies a <code class="literal">WEB-INF/jetty-env.xml</code> file</p></td></tr><tr><td align="left" valign="top"><p><a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/plus/webapp/PlusConfiguration.html" target="_top">org.eclipse.jetty.plus.webapp.PlusConfiguration</a></p></td><td align="left" valign="top"><p>Processes JNDI related aspects of <code class="literal">WEB-INF/web.xml</code> and hooks up naming entries</p></td></tr></tbody></table></div></div><br class="table-break"><p>These configurations must be added in <span class="emphasis"><em>exactly</em></span> the order shown above and should be inserted <span class="emphasis"><em>immediately before</em></span> the <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.html" target="_top">org.eclipse.jetty.webapp.JettyWebXmlConfiguration</a> class in the list of configurations.
To fully support JNDI additional configuration is required, full details of which can be found <a class="link" href="jndi.html" title="Chapter&nbsp;12.&nbsp;Configuring JNDI">here</a>.</p></div><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="_example_annotation_configurations"></a>Example: Annotation Configurations</h5></div></div></div><p>We need just one extra Configuration class to help provide servlet annotation scanning:</p><div class="table"><a name="d0e3028"></a><p class="title"><b>Table&nbsp;4.3.&nbsp;Annotation Configuration classes</b></p><div class="table-contents"><table class="table" summary="Annotation Configuration classes" border="1"><colgroup><col class="col_1"><col class="col_2"></colgroup><tbody><tr><td align="left" valign="top"><p><a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/annotations.AnnotationConfiguration.html" target="_top">org.eclipse.jetty.annotations.AnnotationConfiguration</a></p></td><td align="left" valign="top"><p>Scan container and web app jars looking for @WebServlet, @WebFilter,
@WebListener etc</p></td></tr></tbody></table></div></div><br class="table-break"><p>The above configuration class must be <span class="emphasis"><em>inserted immediately before</em></span> the <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.html" target="_top">org.eclipse.jetty.webapp.JettyWebXmlConfiguration</a> class in the list of configurations.
To fully support annotations additional configuration is require, details of which can be found <a class="link" href="configuring-webapps.html#webapp-context-attributes" title="Other Configuration">below.</a></p></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_how_to_set_the_list_of_configurations"></a>How to Set the List of Configurations</h4></div></div></div><p>You have a number of options for how to make Jetty use a different list of Configurations.</p><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="_setting_the_list_directly_on_the_webappcontext"></a>Setting the list directly on the WebAppContext</h5></div></div></div><p>If you have only one webapp that you wish to affect, this may be the easiest option.
You will, however, either need to have a context xml file that represents your web app, or you need to call the equivalent in code.
Let&#8217;s see an example of how we would add in the Configurations for both JNDI <span class="emphasis"><em>and</em></span> annotations:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"&gt;

&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;

  &lt;Set name="war"&gt;&lt;SystemProperty name="jetty.base" default="."/&gt;/webapps/my-cool-webapp&lt;/Set&gt;

  &lt;Set name="configurationClasses"&gt;
    &lt;Array type="java.lang.String"&gt;
      &lt;Item&gt;org.eclipse.jetty.webapp.WebInfConfiguration&lt;/Item&gt;
      &lt;Item&gt;org.eclipse.jetty.webapp.WebXmlConfiguration&lt;/Item&gt;
      &lt;Item&gt;org.eclipse.jetty.webapp.MetaInfConfiguration&lt;/Item&gt;
      &lt;Item&gt;org.eclipse.jetty.webapp.FragmentConfiguration&lt;/Item&gt;
      &lt;Item&gt;org.eclipse.jetty.plus.webapp.EnvConfiguration&lt;/Item&gt;
      &lt;Item&gt;org.eclipse.jetty.plus.webapp.PlusConfiguration&lt;/Item&gt;
      &lt;Item&gt;org.eclipse.jetty.annotations.AnnotationConfiguration&lt;/Item&gt;
      &lt;Item&gt;org.eclipse.jetty.webapp.JettyWebXmlConfiguration&lt;/Item&gt;
    &lt;/Array&gt;
  &lt;/Set&gt;

&lt;/Configure&gt;</code></pre><p>Of course, you can also use this method to reduce the Configurations applied to a specific <code class="literal">WebAppContext</code>.</p></div><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="_setting_the_list_for_all_webapps_via_the_deployer"></a>Setting the list for all webapps via the Deployer</h5></div></div></div><p>If you use the <a class="link" href="deployment-architecture.html" title="Deployment Architecture">deployer</a>, you can set up the list of Configuration classes on the <a class="link" href="deployment-architecture.html#default-web-app-provider" title="Understanding the Default WebAppProvider">WebAppProvider</a>.
They will then be applied to each <code class="literal">WebAppContext</code> deployed by the deployer:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"&gt;

&lt;Configure id="Server" class="org.eclipse.jetty.server.Server"&gt;

  &lt;Call name="addBean"&gt;
    &lt;Arg&gt;
      &lt;New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager"&gt;
        &lt;Set name="contexts"&gt;
          &lt;Ref refid="Contexts" /&gt;
        &lt;/Set&gt;
        &lt;Call id="webappprovider" name="addAppProvider"&gt;
          &lt;Arg&gt;
            &lt;New class="org.eclipse.jetty.deploy.providers.WebAppProvider"&gt;
              &lt;Set name="monitoredDirName"&gt;&lt;Property name="jetty.base" default="." /&gt;/webapps&lt;/Set&gt;
              &lt;Set name="configurationClasses"&gt;
                &lt;Array type="java.lang.String"&gt;
                  &lt;Item&gt;org.eclipse.jetty.webapp.WebInfConfiguration&lt;/Item&gt;
                  &lt;Item&gt;org.eclipse.jetty.webapp.WebXmlConfiguration&lt;/Item&gt;
                  &lt;Item&gt;org.eclipse.jetty.webapp.MetaInfConfiguration&lt;/Item&gt;
                  &lt;Item&gt;org.eclipse.jetty.webapp.FragmentConfiguration&lt;/Item&gt;
                  &lt;Item&gt;org.eclipse.jetty.plus.webapp.EnvConfiguration&lt;/Item&gt;
                  &lt;Item&gt;org.eclipse.jetty.plus.webapp.PlusConfiguration&lt;/Item&gt;
                  &lt;Item&gt;org.eclipse.jetty.annotations.AnnotationConfiguration&lt;/Item&gt;
                  &lt;Item&gt;org.eclipse.jetty.webapp.JettyWebXmlConfiguration&lt;/Item&gt;
                &lt;/Array&gt;
              &lt;/Set&gt;
            &lt;/New&gt;
          &lt;/Arg&gt;
        &lt;/Call&gt;
      &lt;/New&gt;
    &lt;/Arg&gt;
  &lt;/Call&gt;
&lt;/Configure&gt;</code></pre></div><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="_adding_or_inserting_to_an_existing_list"></a>Adding or inserting to an existing list</h5></div></div></div><p>Instead of having to enumerate the list in its entirety, you can simply nominate classes that you want to add, and indicate whereabouts in the list you want them inserted.
Let&#8217;s look at an example of using this method to add in Configuration support for JNDI - as usual you can either do this in an xml file, or via equivalent code.
This example uses an xml file, in fact it is the <code class="literal">$JETTY_HOME/etc/jetty-plus.xml</code> file from the Jetty distribution:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"&gt;

&lt;Configure id="Server" class="org.eclipse.jetty.server.Server"&gt;

  &lt;!-- =========================================================== --&gt;
  &lt;!-- Add plus Configuring classes to all webapps for this Server --&gt;
  &lt;!-- =========================================================== --&gt;
  &lt;Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="setServerDefault"&gt;
    &lt;Arg&gt;&lt;Ref refid="Server" /&gt;&lt;/Arg&gt;
    &lt;Call name="addAfter"&gt;
      &lt;Arg name="afterClass"&gt;org.eclipse.jetty.webapp.FragmentConfiguration&lt;/Arg&gt;
      &lt;Arg&gt;
        &lt;Array type="String"&gt;
          &lt;Item&gt;org.eclipse.jetty.plus.webapp.EnvConfiguration&lt;/Item&gt;
          &lt;Item&gt;org.eclipse.jetty.plus.webapp.PlusConfiguration&lt;/Item&gt;
        &lt;/Array&gt;
      &lt;/Arg&gt;
    &lt;/Call&gt;
  &lt;/Call&gt;

&lt;/Configure&gt;</code></pre><p>The <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/Configuration.html" target="_top">org.eclipse.jetty.webapp.Configuration.ClassList</a> class provides these methods for insertion:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">addAfter</span></dt><dd>Inserts the supplied list of <code class="literal">Configuration</code> class names after the given Configuration class name.</dd><dt><span class="term">addBefore</span></dt><dd>Inserts the supplied list of <code class="literal">Configuration</code> class names before the given Configuration class name.</dd></dl></div></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="webapp-context-attributes"></a>Other Configuration</h3></div></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="container-include-jar-pattern"></a>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</h4></div></div></div><p>This is a context attribute that can be set on <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/WebAppContext.html" target="_top">an org.eclipse.jetty.webapp.WebAppContext</a> to control which parts of the <span class="emphasis"><em>container&#8217;s</em></span> classpath should be processed for things like annotations, <code class="literal">META-INF/resources</code>, <code class="literal">META-INF/web-fragment.xml</code> and <code class="literal">tlds</code> inside <code class="literal">META-INF</code>.</p><p>Normally, nothing from the container classpath will be included for processing.
However, sometimes you will need to include some.
For example, you may have some libraries that are shared amongst your webapps and thus you have put them into a <code class="literal">$JETTY_HOME/lib</code> directory.
The libraries contain annotations and therefore must be scanned.</p><p>The value of this attribute is a regexp that defines which <span class="emphasis"><em>jars</em></span> and <span class="emphasis"><em>class directories</em></span> from the container&#8217;s classpath should be examined.</p><p>Here&#8217;s an example from a context xml file (although as always, you could have accomplished the same in code), which would match any jar whose name starts with "foo-" or "bar-", or a directory named "classes":</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"&gt;

&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;

    &lt;Call name="setAttribute"&gt;
      &lt;Arg&gt;org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern&lt;/Arg&gt;
      &lt;Arg&gt;.*/foo-[^/]*\.jar$|.*/bar-[^/]*\.jar$|.*/classes/.*&lt;/Arg&gt;
    &lt;/Call&gt;

&lt;/Configure&gt;</code></pre><p>Note that the order of the patterns defines the ordering of the scanning of the jars or class directories.</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="web-inf-include-jar-pattern"></a>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</h4></div></div></div><p>Similarly to the previous context attribute, this attribute controls which jars are processed for things like annotations, <code class="literal">META-INF/resources</code>, <code class="literal">META-INF/web-fragment.xml</code> and <code class="literal">tlds</code> in <code class="literal">META-INF</code>.
However, this attribute controls which jars from the <span class="emphasis"><em>webapp&#8217;s</em></span> classpath (usually <code class="literal">WEB-INF/lib</code>) are processed.
This can be particularly useful when you have dozens of jars in <code class="literal">WEB-INF/lib</code>, but you know that only a few need to be scanned.</p><p>Here&#8217;s an example in a xml file of a pattern that matches any jar that starts with <code class="literal">spring-</code>:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"&gt;

&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;

    &lt;Call name="setAttribute"&gt;
      &lt;Arg&gt;org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern&lt;/Arg&gt;
      &lt;Arg&gt;.*/spring-[^/]*\.jar$&lt;/Arg&gt;
    &lt;/Call&gt;

&lt;/Configure&gt;</code></pre><p>Note that the order of the patterns defines the ordering of the scanning of jar files.</p></div></div></div><script type="text/javascript">
      SyntaxHighlighter.all()
    </script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="configuring-specific-webapp-deployment.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="configuring-deployment.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="static-content-deployment.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Configuring a Specific Web Application Deployment&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Configuring Static Content Deployment</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
            See an error or something missing?
            <span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at
                <span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2016-12-08)</i></span></div></p><script xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-1149868-7']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
    </script></body></html>

Back to the top