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

Jetty/Howto/Avoid slow deployment

< Jetty‎ | Howto
Revision as of 21:09, 21 October 2012 by Janb.intalio.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)



Introduction

Annotations and annotation scanning was added to servlet specification 2.5. Since that time, there has been the possibility that your webapp will need to have all of its classes scanned at deployment to find annotations. The attribute metadata-complete was added in order to prevent unnecessary scanning. If you do not set metadata-complete=true, you risk slow deployment due to annotation scanning. If you have a large number of jars in your webapp, this can be very time consuming.

Since servlet 3.0 (supported by jetty-8.x), there has been the added requirement that both container and webapp jars can be scanned. In fact, even if you do set metadata-complete=true in your web.xml, scanning will probably still occur, due to the requirement to support the new ServletContainerInitializers. See http://java.net/jira/browse/SERVLET_SPEC-36.

This being the case, it is important that you control which jars are scanned in order to cut down deployment time.

Remedy

Jetty allows for the configuration of 2 different context attributes that control which jars are scanned. One controls which container jars are scanned, and the other controls which webapp jars are scanned:

  • org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern. The primary use for this attribute is to control which jars are scanned for tlds in jetty-7. You can find information on which jars to include here: Configuring JSP. In jetty-8, tlds are found via other means and thus this attribute has less importance. Note that if this attribute is *not* set, *no* container jars are scanned. You must set it if you want particular jars scanned.
  • org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern. By default, if this attribute is not set, all jars in WEB-INF/lib will be scanned. You can selectively include jars to be scanned by defining a series of patterns. For example, given this listing of files in WEB-INF/lib:
WEB-INF/lib/
           foo-api-1.2.3.jar
           foo-1.2.3.jar
           bar-0.9.jar
           boo-1.0.jar


<Configure class="org.eclipse.jetty.webapp.WebAppContext">
 
    <Call name="setAttribute">
      <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
      <Arg>.*/.*foo-api-[^/]\.jar$|./.*bar-[^/]\.jar$|./.*wibble[^/]*\.jar$</Arg>
    </Call>
</Configure>

Then the following files would match and be scanned:

WEB-INF/lib/
           foo-api-1.2.3.jar
           bar-0.9.jar

Patterns are specified using java regex expressions.

Context attributes can be set for a single webapp:

Context attributes can be set for multiple webapps by configuring the Deployment Manager.

Back to the top