blob: 8e6d5864202995801a8e14d8db1825f4afed6b1f [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.17">
<meta name="author" content="Jetty Developers">
<title>Eclipse Jetty: Old Documentation</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="./asciidoctor.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="./coderay-asciidoctor.css">
</head>
<body class="article toc2 toc-left">
<div id="header">
<h1>Eclipse Jetty: Old Documentation</h1>
<div class="details">
<span id="author" class="author">Jetty Developers</span><br>
<span id="email" class="email"><a href="mailto:jetty-dev@eclipse.org">jetty-dev@eclipse.org</a></span><br>
<span id="revnumber">version 10.0.10,</span>
<span id="revdate">2022-06-16</span>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Old Jetty Documentation</div>
<ul class="sectlevel1">
<li><a href="#_old-jetty-documentation">OLD JETTY DOCUMENTATION</a></li>
<li><a href="#alpn-chapter">Application Layer Protocol Negotiation (ALPN)</a>
<ul class="sectlevel2">
<li><a href="#alpn">Introducing ALPN</a>
<ul class="sectlevel3">
<li><a href="#alpn-conscrypt">ALPN and Conscrypt</a></li>
<li><a href="#alpn-jdk9">ALPN and JDK 9</a>
<ul class="sectlevel4">
<li><a href="#alpn-osgi">Starting in OSGi</a></li>
</ul>
</li>
<li><a href="#alpn-troubleshooting">ALPN Troubleshooting</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#annotations">Annotations</a>
<ul class="sectlevel2">
<li><a href="#annotations-quick-setup">Quick Setup</a>
<ul class="sectlevel3">
<li><a href="#_jetty-distribution">Jetty Distribution</a></li>
<li><a href="#_jetty-maven-plugin">Jetty Maven Plugin</a></li>
<li><a href="#_embedding">Embedding</a></li>
</ul>
</li>
<li><a href="#using-annotations-embedded">Using Annotations with Jetty Embedded</a>
<ul class="sectlevel3">
<li><a href="#_setting-up-the-classpath">Setting up the Classpath</a></li>
<li><a href="#_example">Example</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#ant-and-jetty">Ant and Jetty</a>
<ul class="sectlevel2">
<li><a href="#jetty-ant">Ant Jetty Plugin</a>
<ul class="sectlevel3">
<li><a href="#jetty-ant-preparation">Preparing Your Project</a></li>
<li><a href="#_preparing-the-build-xml-file">Preparing the <code>build.xml</code> file</a></li>
<li><a href="#_starting-jetty-via-ant">Starting Jetty via Ant</a></li>
<li><a href="#_configuring-the-jetty-container">Configuring the Jetty Container</a></li>
<li><a href="#_deploying-a-web-application">Deploying a Web Application</a>
<ul class="sectlevel4">
<li><a href="#_configuring-the-web-application">Configuring the Web Application</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#architecture">Architecture</a>
<ul class="sectlevel2">
<li><a href="#jetty-classloading">Jetty Classloading</a>
<ul class="sectlevel3">
<li><a href="#configuring-webapp-classloading">Configuring Webapp Classloading</a>
<ul class="sectlevel4">
<li><a href="#controlling-webapp-classloader-priority">Controlling Webapp Classloader Priority</a></li>
<li><a href="#configuring-webapp-caching">Configuring Webapp Classloader Caching</a></li>
<li><a href="#classloading-setting-system-classes">Setting System Classes</a></li>
<li><a href="#setting-server-classes">Setting Server Classes</a></li>
</ul>
</li>
<li><a href="#adding-extra-classpaths">Adding Extra Classpaths to Jetty</a>
<ul class="sectlevel4">
<li><a href="#classpaths-using-start-jar">Using <code>start.jar</code></a></li>
<li><a href="#using-extra-classpath-method">Using the extraClasspath() method</a></li>
</ul>
</li>
<li><a href="#using-custom-webappclassloader">Using a Custom WebAppClassLoader</a></li>
<li><a href="#starting-jetty-custom-classloader">Starting Jetty with a Custom ClassLoader</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#configuring-connectors">Configuring Jetty Connectors</a>
<ul class="sectlevel2">
<li><a href="#jetty-connectors">Connector Configuration Overview</a>
<ul class="sectlevel3">
<li><a href="#_enabling-connectors">Enabling Connectors</a></li>
<li><a href="#_limiting-connections">Limiting Connections</a></li>
<li><a href="#_advanced-configuration">Advanced Configuration</a></li>
<li><a href="#_constructing-a-serverconnector">Constructing a ServerConnector</a></li>
<li><a href="#jetty-connectors-network-settings">Network Settings</a></li>
<li><a href="#jetty-connectors-http-configuration">HTTP Configuration</a></li>
<li><a href="#_ssl-context-configuration">SSL Context Configuration</a></li>
<li><a href="#_proxy-load-balancer-connection-configuration">Proxy / Load Balancer Connection Configuration</a>
<ul class="sectlevel4">
<li><a href="#_x-forward-for-configuration">X-Forward-for Configuration</a></li>
<li><a href="#_proxy-protocol">Proxy Protocol</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#configuring-contexts">Configuring Contexts</a>
<ul class="sectlevel2">
<li><a href="#setting-context-path">Setting a Context Path</a>
<ul class="sectlevel3">
<li><a href="#using-embedded-deployment">Using Embedded Deployment</a></li>
<li><a href="#usng-the-context-provider">By naming convention</a></li>
<li><a href="#using-the-webapp-provider">By Deployer configuration</a></li>
<li><a href="#embedding-web-inf-jetty-web.xml-file">Embedding a WEB-INF/jetty-web.xml File</a></li>
</ul>
</li>
<li><a href="#ref-temporary-directories">Temporary Directories</a>
<ul class="sectlevel3">
<li><a href="#_the-default-temp-directory">The Default Temp Directory</a>
<ul class="sectlevel4">
<li><a href="#_the-location-of-the-temp-directory">The location of the temp directory</a></li>
</ul>
</li>
<li><a href="#_setting-a-specific-temp-directory">Setting a Specific Temp Directory</a>
<ul class="sectlevel4">
<li><a href="#_call-webappcontext-settempdirectorystring-dir">Call WebAppContext.setTempDirectory(String dir)</a></li>
<li><a href="#_setting-the-javax-servlet-context-tempdir-context-attribute">Setting the javax.servlet.context.tempdir Context Attribute</a></li>
<li><a href="#_setting-the-temp-directory-on-the-command-line">Setting the Temp Directory on the Command Line</a></li>
</ul>
</li>
<li><a href="#_the-work-directory">The "work" Directory</a></li>
<li><a href="#_persisting-the-temp-directory">Persisting the temp directory</a></li>
</ul>
</li>
<li><a href="#custom-error-pages">Creating Custom Error Pages</a>
<ul class="sectlevel3">
<li><a href="#_defining-error-pages-in-web-xml">Defining error pages in web.xml</a></li>
<li><a href="#_configuring-error-pages-context-files">Configuring error pages context files</a></li>
<li><a href="#_custom-errorhandler-class">Custom ErrorHandler class</a></li>
<li><a href="#_server-level-404-error">Server level 404 error</a></li>
</ul>
</li>
<li><a href="#setting-form-size">Setting Max Form Size</a>
<ul class="sectlevel3">
<li><a href="#_for-a-single-webapp">For a Single Webapp</a></li>
<li><a href="#_for-all-apps-in-the-jvm">For All Apps in the JVM</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#advanced-debugging">Debugging</a>
<ul class="sectlevel2">
<li><a href="#_options">Options</a></li>
<li><a href="#enable-remote-debugging">Enable remote debugging</a>
<ul class="sectlevel3">
<li><a href="#remote-debugging">Remote Debugging</a>
<ul class="sectlevel4">
<li><a href="#_starting-jetty">Starting Jetty</a></li>
<li><a href="#_linking-with-your-ide">Linking with your IDE</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#debugging-with-intellij">Debugging With IntelliJ</a>
<ul class="sectlevel3">
<li><a href="#_linking-with-intellij">Linking with IntelliJ</a></li>
<li><a href="#intellij-within-intellij">Within IntelliJ</a></li>
</ul>
</li>
<li><a href="#debugging-with-eclipse">Debugging With Eclipse</a>
<ul class="sectlevel3">
<li><a href="#_linking-with-eclipse">Linking with Eclipse</a></li>
<li><a href="#eclipse-within-eclipse">Within Eclipse</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#configuring-deployment">Deploying to Jetty</a>
<ul class="sectlevel2">
<li><a href="#configuring-specific-webapp-deployment">Configuring a Specific Web Application Deployment</a>
<ul class="sectlevel3">
<li><a href="#deployable-descriptor-file">Jetty Deployable Descriptor XML File</a></li>
<li><a href="#using-basic-descriptor-files">Using Basic Descriptor Files</a></li>
<li><a href="#configuring-advanced-descriptor-files">Configuring Advanced Descriptor Files</a></li>
</ul>
</li>
<li><a href="#configuring-webapps">Deployment Processing of WebAppContexts</a>
<ul class="sectlevel3">
<li><a href="#webapp-configurations">Configuration Classes</a>
<ul class="sectlevel4">
<li><a href="#_anatomy-of-a-configuration-class">Anatomy of a Configuration Class</a></li>
<li><a href="#_extending-container-support-by-creating-extra-configurations">Extending Container Support by Creating Extra Configurations</a>
<ul class="sectlevel5">
<li><a href="#jndi-configuration-classes">Example: JNDI Configurations</a></li>
<li><a href="#_example-annotation-configurations">Example: Annotation Configurations</a></li>
</ul>
</li>
<li><a href="#_how-to-set-the-list-of-configurations">How to Set the List of Configurations</a>
<ul class="sectlevel5">
<li><a href="#_setting-the-list-directly-on-the-webappcontext">Setting the list directly on the WebAppContext</a></li>
<li><a href="#_setting-the-list-for-all-webapps-via-the-deployer">Setting the list for all webapps via the Deployer</a></li>
<li><a href="#_adding-or-inserting-to-an-existing-list">Adding or inserting to an existing list</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#webapp-context-attributes">Other Configuration</a>
<ul class="sectlevel4">
<li><a href="#container-include-jar-pattern">org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</a></li>
<li><a href="#web-inf-include-jar-pattern">org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#static-content-deployment">Configuring Static Content Deployment</a></li>
<li><a href="#deployment-architecture">Deployment Architecture</a>
<ul class="sectlevel3">
<li><a href="#udm-application-providers">Application Providers</a></li>
<li><a href="#udm-application-lifecycle-graph">Application LifeCycle Graph</a></li>
<li><a href="#udm-lifecycle-bindings">LifeCycle Bindings</a>
<ul class="sectlevel4">
<li><a href="#_using-globalwebappconfigbinding">Using GlobalWebappConfigBinding</a></li>
</ul>
</li>
<li><a href="#default-web-app-provider">Understanding the Default WebAppProvider</a></li>
</ul>
</li>
<li><a href="#quickstart-webapp">Quickstart Webapps</a>
<ul class="sectlevel3">
<li><a href="#_setting-up-quickstart">Setting up Quickstart</a>
<ul class="sectlevel4">
<li><a href="#_prerequisites">Prerequisites</a>
<ul class="sectlevel5">
<li><a href="#_jetty-distribution-2">Jetty Distribution</a></li>
<li><a href="#_embedded">Embedded</a></li>
</ul>
</li>
<li><a href="#_configuration">Configuration</a>
<ul class="sectlevel5">
<li><a href="#_in-xml">In XML</a></li>
<li><a href="#_in-code">In Code</a></li>
<li><a href="#_pre-generating-the-quickstart-web-xml-file">Pre-generating the quickstart-web.xml file</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_avoiding-tld-scans-with-precompiled-jsps">Avoiding TLD Scans with precompiled JSPs</a></li>
<li><a href="#_bypassing-start-jar">Bypassing start.jar</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#advanced-embedding">Embedding</a>
<ul class="sectlevel2">
<li><a href="#jetty-helloworld">Jetty Embedded HelloWorld</a>
<ul class="sectlevel3">
<li><a href="#downloading-jars">Downloading the Jars</a></li>
<li><a href="#writing-helloworld-example">Writing a HelloWorld Example</a></li>
<li><a href="#compiling-helloworld-example">Compiling the HelloWord example</a></li>
<li><a href="#running-handler-and-server">Running the Handler and Server</a></li>
<li><a href="#next-steps">Next Steps</a></li>
</ul>
</li>
<li><a href="#embedding-jetty">Embedding Jetty</a>
<ul class="sectlevel3">
<li><a href="#_overview">Overview</a></li>
<li><a href="#_creating-the-server">Creating the Server</a></li>
<li><a href="#_using-handlers">Using Handlers</a>
<ul class="sectlevel4">
<li><a href="#_helloworld-handler">HelloWorld Handler</a></li>
<li><a href="#_running-helloworldhandler">Running HelloWorldHandler</a></li>
<li><a href="#_handler-collections-and-wrappers">Handler Collections and Wrappers</a></li>
<li><a href="#_scoped-handlers">Scoped Handlers</a></li>
<li><a href="#_resource-handler">Resource Handler</a></li>
</ul>
</li>
<li><a href="#_embedding-connectors">Embedding Connectors</a>
<ul class="sectlevel4">
<li><a href="#_one-connector">One Connector</a></li>
<li><a href="#_many-connectors">Many Connectors</a></li>
</ul>
</li>
<li><a href="#_embedding-servlets">Embedding Servlets</a></li>
<li><a href="#_embedding-contexts">Embedding Contexts</a></li>
<li><a href="#_embedding-servletcontexts">Embedding ServletContexts</a></li>
<li><a href="#_embedding-web-applications">Embedding Web Applications</a></li>
<li><a href="#_like-jetty-xml">Like Jetty XML</a></li>
</ul>
</li>
<li><a href="#embedded-examples">Embedded Examples</a>
<ul class="sectlevel3">
<li><a href="#embedded-file-server">Simple File Server</a>
<ul class="sectlevel4">
<li><a href="#_run-it">Run it!</a></li>
<li><a href="#_maven-coordinates">Maven Coordinates</a></li>
</ul>
</li>
<li><a href="#embedded-split-file-server">Split File Server</a>
<ul class="sectlevel4">
<li><a href="#_run-it-2">Run it!</a></li>
<li><a href="#_maven-coordinates-2">Maven Coordinates</a></li>
</ul>
</li>
<li><a href="#embedded-many-connectors">Multiple Connectors</a>
<ul class="sectlevel4">
<li><a href="#_walkthrough">Walkthrough</a></li>
<li><a href="#_maven-coordinates-3">Maven Coordinates</a></li>
</ul>
</li>
<li><a href="#embedded-secured-hello-handler">Secured Hello Handler</a>
<ul class="sectlevel4">
<li><a href="#_run-it-3">Run it!</a></li>
<li><a href="#_the-realm-properties-file">The Realm Properties File</a></li>
<li><a href="#_maven-coordinates-4">Maven Coordinates</a></li>
</ul>
</li>
<li><a href="#embedded-minimal-servlet">Minimal Servlet</a>
<ul class="sectlevel4">
<li><a href="#_walkthrough-2">Walkthrough</a></li>
<li><a href="#_maven-coordinates-5">Maven Coordinates</a></li>
</ul>
</li>
<li><a href="#embedded-one-webapp">Web Application</a>
<ul class="sectlevel4">
<li><a href="#_run-it-4">Run it!</a></li>
<li><a href="#_maven-coordinates-6">Maven Coordinates</a></li>
</ul>
</li>
<li><a href="#embedded-webapp-jsp">Web Application with JSP</a>
<ul class="sectlevel4">
<li><a href="#_run-it-5">Run it!</a></li>
<li><a href="#_maven-coordinates-7">Maven Coordinates</a></li>
</ul>
</li>
<li><a href="#adding-embedded-examples">Adding Examples</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#advanced-extras">Provided Servlets, Filters, and Handlers</a>
<ul class="sectlevel2">
<li><a href="#default-servlet">Default Servlet</a>
<ul class="sectlevel3">
<li><a href="#default-servlet-metadata">Info</a></li>
<li><a href="#default-servlet-usage">Usage</a></li>
<li><a href="#default-servlet-init">Init Parameters</a></li>
</ul>
</li>
<li><a href="#proxy-servlet">Proxy Servlet</a>
<ul class="sectlevel3">
<li><a href="#proxy-servlet-metadata">Info</a></li>
<li><a href="#proxy-servlet-usage">Usage</a></li>
<li><a href="#proxy-servlet-init">Init Parameters</a></li>
</ul>
</li>
<li><a href="#balancer-servlet">Balancer Servlet</a>
<ul class="sectlevel3">
<li><a href="#balancer-servlet-metadata">Info</a></li>
<li><a href="#balancer-servlet-usage">Usage</a></li>
</ul>
</li>
<li><a href="#cgi-servlet">CGI Servlet</a>
<ul class="sectlevel3">
<li><a href="#cgi-servlet-metadata">Info</a></li>
<li><a href="#cgi-servlet-usage">Usage</a></li>
</ul>
</li>
<li><a href="#qos-filter">Quality of Service Filter</a>
<ul class="sectlevel3">
<li><a href="#qos-filter-metadata">Info</a></li>
<li><a href="#qos-filter-usage">Usage</a></li>
<li><a href="#qos-understanding">Understanding the Problem</a>
<ul class="sectlevel4">
<li><a href="#_waiting-for-resources">Waiting for Resources</a></li>
<li><a href="#_prioritizing-resources">Prioritizing Resources</a></li>
</ul>
</li>
<li><a href="#qos-applying">Applying the QoSFilter</a>
<ul class="sectlevel4">
<li><a href="#_required-jars">Required JARs</a></li>
<li><a href="#_sample-configuration">Sample Configuration</a></li>
<li><a href="#qos-filter-init">Configuring QoS Filter Parameters</a></li>
<li><a href="#_mapping-to-urls">Mapping to URLs</a></li>
<li><a href="#_setting-the-request-priority">Setting the Request Priority</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#dos-filter">Denial of Service Filter</a>
<ul class="sectlevel3">
<li><a href="#dos-filter-metadata">Info</a></li>
<li><a href="#dos-filter-usage">Usage</a></li>
<li><a href="#dos-filter-using">Using the DoS Filter</a>
<ul class="sectlevel4">
<li><a href="#_required-jars-2">Required JARs</a></li>
<li><a href="#_sample-configuration-2">Sample Configuration</a></li>
<li><a href="#dos-filter-init">Configuring DoS Filter Parameters</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#header-filter">Header Filter</a>
<ul class="sectlevel3">
<li><a href="#header-filter-metadata">Info</a></li>
<li><a href="#header-filter-usage">Usage</a>
<ul class="sectlevel4">
<li><a href="#_required-jars-3">Required JARs</a></li>
<li><a href="#_sample-configuration-3">Sample Configuration</a></li>
<li><a href="#header-filter-init">Configuring Header Filter Parameters</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#gzip-filter">Gzip Handler</a>
<ul class="sectlevel3">
<li><a href="#gzip-filter-metadata">Info</a></li>
<li><a href="#gzip-filter-usage">Usage</a></li>
<li><a href="#gzip-filter-rules">Gzip Rules</a></li>
<li><a href="#gzip-filter-init">Gzip Configuration</a></li>
</ul>
</li>
<li><a href="#cross-origin-filter">Cross Origin Filter</a>
<ul class="sectlevel3">
<li><a href="#cross-origin-filter-metadata">Info</a></li>
<li><a href="#cross-origin-filter-usage">Usage</a></li>
<li><a href="#cross-origin-setup">Setup</a></li>
<li><a href="#cross-origin-config">Configuration</a></li>
</ul>
</li>
<li><a href="#resource-handler">Resource Handler</a>
<ul class="sectlevel3">
<li><a href="#resource-handler-metadata">Info</a></li>
<li><a href="#resource-handler-usage">Usage</a></li>
<li><a href="#_improving-the-look-and-feel">Improving the Look and Feel</a></li>
<li><a href="#_embedded-example">Embedded Example</a></li>
</ul>
</li>
<li><a href="#debug-handler">Debug Handler</a>
<ul class="sectlevel3">
<li><a href="#debug-handler-metadata">Info</a></li>
<li><a href="#debug-handler-usage">Usage</a></li>
<li><a href="#_usage-in-standard-distribution">Usage in Standard Distribution</a></li>
<li><a href="#_embedded-usage">Embedded usage</a></li>
<li><a href="#_example-output">Example output</a></li>
</ul>
</li>
<li><a href="#statistics-handler">Statistics Handler</a>
<ul class="sectlevel3">
<li><a href="#statistics-handler-metadata">Info</a></li>
<li><a href="#statistics-handler-usage">Usage</a></li>
<li><a href="#request-statistics">Request Statistics</a></li>
<li><a href="#connection-statistics">Connection Statistics</a></li>
<li><a href="#session-statistics">Session Statistics</a></li>
</ul>
</li>
<li><a href="#inetaccess-handler">InetAccess Handler</a>
<ul class="sectlevel3">
<li><a href="#inetaccess-handler-metadata">Info</a></li>
<li><a href="#inetaccess-handler-usage">Usage</a></li>
<li><a href="#_usage-in-standard-distribution-2">Usage in Standard Distribution</a></li>
</ul>
</li>
<li><a href="#moved-context-handler">Moved Context Handler</a>
<ul class="sectlevel3">
<li><a href="#moved-context-handler-metadata">Info</a></li>
<li><a href="#moved-context-handler-usage">Usage</a></li>
</ul>
</li>
<li><a href="#shutdown-handler">Shutdown Handler</a>
<ul class="sectlevel3">
<li><a href="#shutdown-handler-metadata">Info</a></li>
<li><a href="#shutdown-handler-usage">Usage</a></li>
</ul>
</li>
<li><a href="#default-handler">Default Handler</a>
<ul class="sectlevel3">
<li><a href="#default-handler-metadata">Info</a></li>
<li><a href="#default-handler-usage">Usage</a></li>
</ul>
</li>
<li><a href="#error-handler">Error Handler</a>
<ul class="sectlevel3">
<li><a href="#error-handler-metadata">Info</a></li>
<li><a href="#error-handler-usage">Usage</a></li>
</ul>
</li>
<li><a href="#rewrite-handler">Rewrite Handler</a>
<ul class="sectlevel3">
<li><a href="#rewrite-handler-metadata">Info</a></li>
<li><a href="#_usage">Usage</a>
<ul class="sectlevel4">
<li><a href="#_embedded-example-2">Embedded Example</a></li>
</ul>
</li>
<li><a href="#rewrite-rules">Rules</a>
<ul class="sectlevel4">
<li><a href="#_patternrule">PatternRule</a></li>
<li><a href="#_regexrule">RegexRule</a></li>
<li><a href="#_headerrule">HeaderRule</a></li>
<li><a href="#_others">Others</a></li>
<li><a href="#_rulecontainer">RuleContainer</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#fastcgi">FastCGI Support</a>
<ul class="sectlevel2">
<li><a href="#fastcgi-intro">FastCGI Introduction</a></li>
<li><a href="#configuring-fastcgi">Configuring Jetty for FastCGI</a>
<ul class="sectlevel3">
<li><a href="#configuring-fastcgi-http2">Configuring Jetty to Proxy HTTP/2 to FastCGI</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#frameworks">Frameworks</a>
<ul class="sectlevel2">
<li><a href="#framework-cdi">CDI</a>
<ul class="sectlevel3">
<li><a href="#_jetty-cdi-modules">Jetty CDI Modules</a>
<ul class="sectlevel4">
<li><a href="#_jetty-cdi-module">Jetty <code>cdi</code> Module</a></li>
<li><a href="#_jetty-cdi-decorate-module">Jetty <code>cdi-decorate</code> Module</a></li>
<li><a href="#_jetty-cdi-spi-module">Jetty <code>cdi-spi</code> Module</a></li>
<li><a href="#_jetty-cdi2-module">Jetty <code>cdi2</code> Module</a></li>
</ul>
</li>
<li><a href="#cdi-embedded">Embedded Jetty with CDI</a></li>
</ul>
</li>
<li><a href="#framework-jetty-osgi">OSGI</a>
<ul class="sectlevel3">
<li><a href="#_introduction">Introduction</a></li>
<li><a href="#_general-setup">General Setup</a></li>
<li><a href="#_the-jetty-osgi-container">The Jetty OSGi Container</a>
<ul class="sectlevel4">
<li><a href="#_the-jetty-osgi-boot-jar">The jetty-osgi-boot jar</a></li>
<li><a href="#customize-jetty-container">Customizing the Jetty Container</a></li>
<li><a href="#_the-jetty-container-as-an-osgi-service">The Jetty Container as an OSGi Service</a></li>
<li><a href="#_adding-more-jetty-servers">Adding More Jetty Servers</a></li>
</ul>
</li>
<li><a href="#_deploying-bundles-as-webapps">Deploying Bundles as Webapps</a>
<ul class="sectlevel4">
<li><a href="#_determining-the-context-path-for-a-webapp-bundle">Determining the Context Path for a Webapp Bundle</a></li>
<li><a href="#_extra-properties-available-for-webapp-bundles">Extra Properties Available for Webapp Bundles</a></li>
</ul>
</li>
<li><a href="#_deploying-bundles-as-jetty-contexthandlers">Deploying Bundles as Jetty ContextHandlers</a>
<ul class="sectlevel4">
<li><a href="#_determining-the-context-path-for-a-contexthandler-bundle">Determining the Context Path for a ContextHandler Bundle</a></li>
<li><a href="#_extra-properties-available-for-context-xml-files">Extra Properties Available for Context Xml Files</a></li>
</ul>
</li>
<li><a href="#services-as-webapps">Deploying Services as Webapps</a></li>
<li><a href="#_deploying-services-as-contexthandlers">Deploying Services as ContextHandlers</a>
<ul class="sectlevel4">
<li><a href="#_extra-properties-available-for-context-xml-files-2">Extra Properties Available for Context Xml Files</a></li>
</ul>
</li>
<li><a href="#_support-for-the-osgi-service-platform-enterprise-specification">Support for the OSGi Service Platform Enterprise Specification</a>
<ul class="sectlevel4">
<li><a href="#_context-attributes">Context Attributes</a></li>
<li><a href="#_service-attributes">Service Attributes</a></li>
<li><a href="#_osgi-events">OSGi Events</a></li>
</ul>
</li>
<li><a href="#_using-jsps">Using JSPs</a>
<ul class="sectlevel4">
<li><a href="#_setup">Setup</a></li>
<li><a href="#_the-jetty-osgi-boot-jsp-jar">The jetty-osgi-boot-jsp jar</a>
<ul class="sectlevel5">
<li><a href="#_using-taglibs">Using TagLibs</a></li>
<li><a href="#_container-path-taglibs">Container Path Taglibs</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#osgi-annotations">Using Annotations/ServletContainerInitializers</a></li>
<li><a href="#_osgi-containers">OSGi Containers</a>
<ul class="sectlevel4">
<li><a href="#_felix">Felix</a></li>
<li><a href="#_eclipse">Eclipse</a>
<ul class="sectlevel5">
<li><a href="#_eclipse-update-site">Eclipse Update Site</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#framework-metro">Metro</a>
<ul class="sectlevel3">
<li><a href="#metro-setup-distro">Metro Setup</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#introduction">Introducing Jetty</a>
<ul class="sectlevel2">
<li><a href="#what-is-jetty">What is Jetty?</a></li>
<li><a href="#what-jetty-version">What Version Do I Use?</a></li>
<li><a href="#jetty-javaee">Jetty and Java EE Web Profile</a>
<ul class="sectlevel3">
<li><a href="#jetty-javaee-7">Java EE 7 Web Profile</a></li>
<li><a href="#jetty-javaee-6">Jetty EE 6 Web Profile</a></li>
</ul>
</li>
<li><a href="#quickstart-jetty-coordinates">Finding Jetty in Maven</a>
<ul class="sectlevel3">
<li><a href="#_maven-coordinates-8">Maven Coordinates</a></li>
<li><a href="#_changelogs-in-maven-central">Changelogs in Maven Central</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#quick-start-getting-started">Using Jetty</a>
<ul class="sectlevel2">
<li><a href="#jetty-downloading">Downloading Jetty</a>
<ul class="sectlevel3">
<li><a href="#_downloading-the-jetty-distribution">Downloading the Jetty Distribution</a>
<ul class="sectlevel4">
<li><a href="#distribution-content">Distribution Content</a></li>
</ul>
</li>
<li><a href="#jetty-home-downloading">Downloading the Jetty-Home Distribution</a>
<ul class="sectlevel4">
<li><a href="#jetty-home-distribution-content">Distribution Content</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#quickstart-running-jetty">Running Jetty</a>
<ul class="sectlevel3">
<li><a href="#demo-webapps-base">Demo Base</a></li>
</ul>
</li>
<li><a href="#quickstart-common-config">Common Jetty Configuration</a>
<ul class="sectlevel3">
<li><a href="#creating-jetty-base">Creating a new Jetty Base</a></li>
<li><a href="#quickstart-changing-jetty-port">Changing the Jetty Port</a></li>
<li><a href="#quickstart-starting-https">Adding SSL for HTTPS &amp; HTTP2</a>
<ul class="sectlevel4">
<li><a href="#quickstart-changing-https-port">Changing the Jetty HTTPS Port</a></li>
</ul>
</li>
<li><a href="#_more-start-jar-options">More start.jar Options</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#quick-start-configure">An Introduction to Jetty Configuration</a>
<ul class="sectlevel2">
<li><a href="#quickstart-config-what">What to Configure in Jetty</a>
<ul class="sectlevel3">
<li><a href="#intro-jetty-configuration-server">Configuring the Server</a></li>
<li><a href="#intro-jetty-configuration-connectors">Configuring Connectors</a></li>
<li><a href="#intro-jetty-configuration-contexts">Configuring Contexts</a>
<ul class="sectlevel4">
<li><a href="#_context-configuration-by-api">Context Configuration by API</a></li>
<li><a href="#_context-configuration-by-ioc-xml">Context Configuration by IoC XML</a></li>
<li><a href="#intro-jetty-configuration-webapps">Configuring Web Applications</a></li>
<li><a href="#_setting-the-context-path">Setting the Context Path</a></li>
<li><a href="#quickstart-config-deployer">Web Application Deployment</a></li>
<li><a href="#_setting-an-authentication-realm">Setting an Authentication Realm</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#upgrading-jetty">Upgrading Jetty</a></li>
<li><a href="#http2">HTTP/2</a>
<ul class="sectlevel2">
<li><a href="#http2-configuring-push">Configuring HTTP/2 Push</a></li>
</ul>
</li>
<li><a href="#reference-section">Jetty XML Reference</a>
<ul class="sectlevel2">
<li><a href="#jetty-xml-usage">Jetty XML Usage</a>
<ul class="sectlevel3">
<li><a href="#using-jettyxml">Using jetty.xml</a></li>
<li><a href="#using-multiple-configuration-files">Using Multiple Configuration Files</a></li>
<li><a href="#setting-parameters-in-configuration-files">Setting Parameters in Configuration Files</a></li>
</ul>
</li>
<li><a href="#jetty-xml-config">jetty.xml</a>
<ul class="sectlevel3">
<li><a href="#root-element-jetty-xml">Root Element</a></li>
<li><a href="#jetty-xml-examples">Examples</a></li>
<li><a href="#jetty-xml-additional-resources">Additional Resources</a></li>
</ul>
</li>
<li><a href="#jetty-web-xml-config">jetty-web.xml</a>
<ul class="sectlevel3">
<li><a href="#root-element-jetty-web-xml">Root Element</a></li>
<li><a href="#using-jetty-web-xml">Using jetty-web.xml</a></li>
<li><a href="#jetty-web-xml-examples">jetty-web.xml Examples</a></li>
<li><a href="#additional-jetty-web-xml-resources">Additional <code>jetty-web.xml</code> Resources</a></li>
</ul>
</li>
<li><a href="#jetty-env-xml">jetty-env.xml</a>
<ul class="sectlevel3">
<li><a href="#jetty-env-root-element">jetty-env.xml Root Element</a></li>
<li><a href="#using-jetty-env-xml">Using <code>jetty-env.xml</code></a></li>
<li><a href="#additional-jetty-env-xml-resources">Additional jetty-env.xml Resources</a></li>
</ul>
</li>
<li><a href="#webdefault-xml">webdefault.xml</a>
<ul class="sectlevel3">
<li><a href="#using-webdefault-xml">Using webdefault.xml</a>
<ul class="sectlevel4">
<li><a href="#creating-custom-webdefault-xml-one-webapp">Creating a Custom webdefault.xml for One WebApp</a></li>
<li><a href="#creating-custom-webdefault-xml-multiple-webapps">Creating a Custom webdefault.xml for Multiple WebApps</a></li>
<li><a href="#webdefault-xml-using-jetty-maven-plugin">Using the Jetty Maven Plugin</a></li>
<li><a href="#webdefault-xml-additional-resources">Additional Resources</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#override-web-xml">Jetty override-web.xml</a>
<ul class="sectlevel3">
<li><a href="#using-override-web-xml">Using override-web.xml</a></li>
<li><a href="#override-using-jetty-maven-plugin">Using the Jetty Maven Plugin</a></li>
<li><a href="#override-web-xml-additional-resources">Additional Resources</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#jmx-chapter">Java Management Extensions (JMX)</a>
<ul class="sectlevel2">
<li><a href="#jetty-jmx-annotations">Jetty JMX Annotations</a>
<ul class="sectlevel3">
<li><a href="#jmx-annotation-introspection">Annotation Introspection</a></li>
<li><a href="#jmx-managed-object">@ManagedObject</a></li>
<li><a href="#jmx-managed-attribute">@ManagedAttribute</a></li>
<li><a href="#jmx-managed-operation">@ManagedOperation</a></li>
<li><a href="#jmx-name-annotation">@Name</a></li>
<li><a href="#jmx-annotation-example">Example</a></li>
</ul>
</li>
<li><a href="#jetty-jconsole">Managing Jetty with JConsole and JMC</a>
<ul class="sectlevel3">
<li><a href="#_starting-jetty-standalone">Starting Jetty Standalone</a></li>
<li><a href="#jetty-jconsole-monitoring">Monitoring Jetty with JConsole</a>
<ul class="sectlevel4">
<li><a href="#_connecting-to-your-server-process">Connecting to your server process</a></li>
</ul>
</li>
<li><a href="#_managing-jetty-objects-with-jconsole">Managing Jetty Objects with JConsole</a></li>
<li><a href="#jetty-jmc-monitoring">Monitoring Jetty with JMC</a>
<ul class="sectlevel4">
<li><a href="#_connecting-to-your-server-process-2">Connecting to your server process</a></li>
</ul>
</li>
<li><a href="#_managing-jetty-objects-with-jconsole-2">Managing Jetty Objects with JConsole</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#jndi">Configuring JNDI</a>
<ul class="sectlevel2">
<li><a href="#using-jetty-jndi">Working with Jetty JNDI</a>
<ul class="sectlevel3">
<li><a href="#_defining-the-web-xml">Defining the web.xml</a></li>
<li><a href="#defining-jndi-naming-entries">Declaring Resources</a></li>
<li><a href="#jndi-where-to-declare">Deciding Where to Declare Resources</a></li>
<li><a href="#jndi-name-scope">Scope of Resource Names</a></li>
<li><a href="#binding-objects-into-jetty-jndi">What Can Be Bound as a Resource?</a></li>
</ul>
</li>
<li><a href="#jndi-configuration">Configuring JNDI</a>
<ul class="sectlevel3">
<li><a href="#configuring-jndi-env-entries">Configuring JNDI <em>env-entries</em></a></li>
<li><a href="#configuring-resource-refs-and-resource-env-refs">Configuring <em>resource-refs</em> and <em>resource-env-refs</em></a></li>
<li><a href="#configuring-datasources">Configuring DataSources</a></li>
<li><a href="#configuring-jms-queues-topics-connectionfactories">Configuring JMS Queues, Topics and ConnectionFactories</a></li>
<li><a href="#configuring-mail-with-jndi">Configuring Mail</a></li>
<li><a href="#configuring-xa-transactions">Configuring XA Transactions</a></li>
<li><a href="#configuring-links">Configuring Links</a></li>
</ul>
</li>
<li><a href="#jndi-embedded">Using JNDI with Jetty Embedded</a>
<ul class="sectlevel3">
<li><a href="#_setting-up-the-classpath-2">Setting up the Classpath</a></li>
<li><a href="#_example-code">Example Code</a></li>
</ul>
</li>
<li><a href="#jndi-datasource-examples">Datasource Examples</a>
<ul class="sectlevel3">
<li><a href="#pooling-datasources">Pooling DataSources</a>
<ul class="sectlevel4">
<li><a href="#hikaricp-datasource">HikariCP</a></li>
<li><a href="#bonecp-datasource">BoneCP</a></li>
<li><a href="#c3p0-datasource">c3p0</a></li>
<li><a href="#dbcp-datasource">DBCP</a></li>
<li><a href="#atomikos-datasource">Atomikos 3.3.2+</a></li>
<li><a href="#mysql-pooled-datasource">MySQL</a></li>
<li><a href="#postgreSQL-pooled-datasource">PostgreSQL</a></li>
<li><a href="#DB2-pooled-datasource">DB2</a></li>
</ul>
</li>
<li><a href="#non-pooling-datasources">Non-pooling DataSources</a>
<ul class="sectlevel4">
<li><a href="#sql-server-2000-datasource">SQL Server 2000</a></li>
<li><a href="#oracle-9i10g-datasource">Oracle 9i/10g</a></li>
<li><a href="#postgreSQL-datasource">PostgreSQL</a></li>
<li><a href="#sybase-datasource">Sybase</a></li>
<li><a href="#DB2-datasource">DB2</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#configuring-jsp">Configuring JSP Support</a>
<ul class="sectlevel2">
<li><a href="#jsp-support">Configuring JSP</a>
<ul class="sectlevel3">
<li><a href="#which-jsp-implementation">Which JSP Implementation</a>
<ul class="sectlevel4">
<li><a href="#_logging">Logging</a></li>
<li><a href="#_jsps-and-embedding">JSPs and Embedding</a></li>
</ul>
</li>
<li><a href="#_precompiling-jsps">Precompiling JSPs</a>
<ul class="sectlevel4">
<li><a href="#compiling-jsps">Apache JSP Container</a></li>
<li><a href="#configuring-jsp-for-jetty">Configuration</a></li>
</ul>
</li>
<li><a href="#modifying-configuration">Modifying Configuration</a>
<ul class="sectlevel4">
<li><a href="#overriding-webdefault.xml">Overriding <code>webdefault.xml</code></a></li>
<li><a href="#configuring-jsp-servlet-in-web.xml">Configuring the JSP Servlet in web.xml</a></li>
<li><a href="#jsp-async-support">Configuring Async Support</a></li>
</ul>
</li>
<li><a href="#using-jstl-taglibs-for-jetty7-jetty8">Using JSTL Taglibs</a>
<ul class="sectlevel4">
<li><a href="#_embedding-2">Embedding</a>
<ul class="sectlevel5">
<li><a href="#_apache-jsp">Apache JSP</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#using-jsf-taglibs">Using JSF Taglibs</a>
<ul class="sectlevel4">
<li><a href="#using-jsf-taglibs-with-jetty-standalone">Using JSF Taglibs with Jetty Distribution</a></li>
<li><a href="#using-jsf-taglibs-with-jetty-maven-plugin">Using JSF Taglibs with Jetty Maven Plugin</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#configuring-logging">Jetty Logging</a>
<ul class="sectlevel2">
<li><a href="#configuring-jetty-logging">Configuring Jetty Logging</a>
<ul class="sectlevel3">
<li><a href="#selecting-log-framework">Selecting the Log Framework</a></li>
<li><a href="#configuring-jetty-stderrlog">The jetty-logging.properties file</a></li>
</ul>
</li>
<li><a href="#default-logging-with-stderrlog">Default Logging with Jetty&#8217;s StdErrLog</a>
<ul class="sectlevel3">
<li><a href="#stderrlog-configuration">StdErrLog Configuration</a></li>
<li><a href="#deprecated-parameters">Deprecated Parameters</a></li>
</ul>
</li>
<li><a href="#configuring-logging-modules">Jetty Logging Integrations (SLF4J, Log4j, Logback, JCL, JUL)</a>
<ul class="sectlevel3">
<li><a href="#example-logging-slf4j">Logging with SLF4J</a></li>
<li><a href="#example-logging-log4j">Logging with Log4j and Log4j2</a></li>
<li><a href="#example-logging-logback">Logging with Logback</a></li>
<li><a href="#_logging-with-java-util-logging">Logging with Java Util Logging</a>
<ul class="sectlevel4">
<li><a href="#example-logging-java-util-logging">Java Util Logging with SLF4J</a></li>
</ul>
</li>
<li><a href="#_capturing-console-output">Capturing Console Output</a></li>
</ul>
</li>
<li><a href="#example-logging-logback-centralized">Centralized Logging using Logback</a></li>
<li><a href="#jetty-maven-scanning">Files Scanned by the Jetty Maven Plugin</a>
<ul class="sectlevel3">
<li><a href="#scanner-matrix">Scanner Matrix</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#platforms">Platforms, Stacks and Alternative Distributions</a>
<ul class="sectlevel2">
<li><a href="#_many-many-options">Many many options&#8230;&#8203;</a></li>
<li><a href="#jelastic">Jelastic</a></li>
<li><a href="#cloudfoundry">CloudFoundry</a>
<ul class="sectlevel3">
<li><a href="#cloudfoundry-overview">Overview</a></li>
<li><a href="#cloudfoundry-usage">Usage</a></li>
<li><a href="#cloudfoundry-acknowledgements">Acknowledgements</a></li>
</ul>
</li>
<li><a href="#elastic-beanstalk">Amazon Elastic Beanstalk</a>
<ul class="sectlevel3">
<li><a href="#elastic-beanstalk-overview">Overview</a></li>
<li><a href="#elastic-beanstalk-maven">Maven Bits</a></li>
</ul>
</li>
<li><a href="#fedora">Fedora</a></li>
<li><a href="#ubuntu">Ubuntu</a></li>
</ul>
</li>
<li><a href="#runner">Jetty Runner</a>
<ul class="sectlevel2">
<li><a href="#jetty-runner">Use Jetty Without an Installed Distribution</a>
<ul class="sectlevel3">
<li><a href="#jetty-runner-preparation">Preparation</a></li>
<li><a href="#_deploying-a-simple-context">Deploying a Simple Context</a></li>
<li><a href="#_deploying-multiple-contexts">Deploying Multiple Contexts</a>
<ul class="sectlevel4">
<li><a href="#_changing-the-default-port">Changing the Default Port</a></li>
<li><a href="#_using-jetty-xml-files">Using jetty.xml Files</a></li>
</ul>
</li>
<li><a href="#runner-configuration-reference">Full Configuration Reference</a>
<ul class="sectlevel4">
<li><a href="#_printing-the-version">Printing the Version</a></li>
<li><a href="#_configuring-a-request-log">Configuring a Request Log</a></li>
<li><a href="#_configuring-the-output-log">Configuring the Output Log</a></li>
<li><a href="#_configuring-the-interface-for-http">Configuring the Interface for HTTP</a></li>
<li><a href="#_configuring-the-port-for-http">Configuring the Port for HTTP</a></li>
<li><a href="#_configuring-stop">Configuring Stop</a></li>
<li><a href="#_configuring-the-container-classpath">Configuring the Container Classpath</a></li>
<li><a href="#_gathering-statistics">Gathering Statistics</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#configuring-security">Configuring Security</a>
<ul class="sectlevel2">
<li><a href="#configuring-security-authentication">Authentication and Authorization</a>
<ul class="sectlevel3">
<li><a href="#_configuring-an-authentication-mechanism">Configuring an Authentication mechanism</a></li>
<li><a href="#security-realms">Security Realms</a></li>
<li><a href="#_scoping-security-realms">Scoping Security Realms</a>
<ul class="sectlevel4">
<li><a href="#_globally-scoped">Globally Scoped</a></li>
<li><a href="#_per-webapp-scoped">Per-Webapp Scoped</a></li>
</ul>
</li>
<li><a href="#configuring-login-service">Configuring a LoginService</a>
<ul class="sectlevel4">
<li><a href="#hash-login-service">HashLoginService</a></li>
<li><a href="#jdbc-login-service">JDBCLoginService</a></li>
</ul>
</li>
<li><a href="#_authorization">Authorization</a>
<ul class="sectlevel4">
<li><a href="#_configuring-authorization-with-context-xml-files">Configuring Authorization with Context XML Files</a></li>
</ul>
</li>
<li><a href="#_authentication-and-authorization-with-embedded-jetty">Authentication and Authorization with Embedded Jetty</a></li>
<li><a href="#_jsr-196-java-authentication-service-provider-interface-for-containers-jaspi">JSR 196: Java Authentication Service Provider Interface for Containers (JASPI)</a></li>
</ul>
</li>
<li><a href="#configuring-form-size">Limiting Form Content</a>
<ul class="sectlevel3">
<li><a href="#_configuring-form-limits-for-a-webapp">Configuring Form Limits for a Webapp</a></li>
<li><a href="#_configuring-form-limits-for-the-server">Configuring Form Limits for the Server</a></li>
</ul>
</li>
<li><a href="#serving-aliased-files">Aliased Files and Symbolic links</a>
<ul class="sectlevel3">
<li><a href="#_good-security-practise">Good Security Practise</a></li>
<li><a href="#file-alias-detection">Alias detection</a></li>
<li><a href="#file-alias-serving">Serving Aliases and Symbolic Links</a></li>
</ul>
</li>
<li><a href="#configuring-security-secure-passwords">Secure Password Obfuscation</a></li>
<li><a href="#setting-port80-access">Setting Port 80 Access for a Non-Root User</a>
<ul class="sectlevel3">
<li><a href="#using-ipchains">Using ipchains</a></li>
<li><a href="#using-iptables">Using iptables</a></li>
<li><a href="#configuring-jetty-setuid-feature">Configuring Jetty&#8217;s SetUID Feature</a></li>
<li><a href="#using-solaris10-user-rights-management-framework">Using the Solaris 10 User Rights Management Framework</a></li>
</ul>
</li>
<li><a href="#jaas-support">JAAS Support</a>
<ul class="sectlevel3">
<li><a href="#jetty-jaas">Jetty and JAAS</a></li>
<li><a href="#jaas-configuration">Configuration</a>
<ul class="sectlevel4">
<li><a href="#_step-1">Step 1</a></li>
<li><a href="#jaas-step-2">Step 2</a></li>
<li><a href="#_step-3">Step 3</a></li>
</ul>
</li>
<li><a href="#_a-closer-look-at-jaasloginservice">A Closer Look at JAASLoginService</a>
<ul class="sectlevel4">
<li><a href="#_callbackhandler">CallbackHandler</a></li>
<li><a href="#_role-principal-implementation-class">Role Principal Implementation Class</a></li>
<li><a href="#_sample-loginmodules">Sample LoginModules</a></li>
<li><a href="#_jdbcloginmodule">JDBCLoginModule</a></li>
<li><a href="#_datasourceloginmodule">DataSourceLoginModule</a></li>
<li><a href="#_propertyfileloginmodule">PropertyFileLoginModule</a></li>
<li><a href="#_ldaploginmodule">LdapLoginModule</a></li>
</ul>
</li>
<li><a href="#_writing-your-own-loginmodule">Writing your Own LoginModule</a></li>
<li><a href="#_other-goodies">Other Goodies</a>
<ul class="sectlevel4">
<li><a href="#_servletrequestcallback">ServletRequestCallback</a></li>
<li><a href="#_requestparametercallback">RequestParameterCallback</a></li>
<li><a href="#_example-jaas-webapp">Example JAAS WebApp</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#spnego-support">SPNEGO Support</a>
<ul class="sectlevel3">
<li><a href="#_configuring-jetty-and-spnego">Configuring Jetty and SPNEGO</a></li>
<li><a href="#_configuring-firefox">Configuring Firefox</a></li>
<li><a href="#_configuring-internet-explorer">Configuring Internet Explorer</a></li>
</ul>
</li>
<li><a href="#openid-support">OpenID Support</a>
<ul class="sectlevel3">
<li><a href="#_external-setup">External Setup</a>
<ul class="sectlevel4">
<li><a href="#_registering-an-app-with-openid-provider">Registering an App with OpenID Provider</a></li>
</ul>
</li>
<li><a href="#_distribution-configuration">Distribution Configuration</a>
<ul class="sectlevel4">
<li><a href="#_openid-provider-configuration">OpenID Provider Configuration</a></li>
<li><a href="#_webapp-specific-configuration-in-web-xml">WebApp Specific Configuration in web.xml</a></li>
</ul>
</li>
<li><a href="#_embedded-configuration">Embedded Configuration</a>
<ul class="sectlevel4">
<li><a href="#_define-the-openidconfiguration-for-a-specific-openid-provider">Define the <code>OpenIdConfiguration</code> for a specific OpenID Provider.</a></li>
<li><a href="#_configuring-an-openidloginservice">Configuring an <code>OpenIdLoginService</code></a></li>
<li><a href="#_configuring-an-openidauthenticator-with-openidconfiguration-and-error-page-redirect">Configuring an <code>OpenIdAuthenticator</code> with <code>OpenIdConfiguration</code> and Error Page Redirect</a></li>
<li><a href="#_usage-2">Usage</a>
<ul class="sectlevel5">
<li><a href="#_claims-and-access-token">Claims and Access Token</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_scopes">Scopes</a></li>
<li><a href="#_roles">Roles</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#startup">Starting Jetty</a>
<ul class="sectlevel2">
<li><a href="#startup-unix-service">Startup a Unix Service using jetty.sh</a>
<ul class="sectlevel3">
<li><a href="#_quick-start-a-jetty-service">Quick-Start a Jetty Service</a></li>
<li><a href="#_practical-setup-of-a-jetty-service">Practical Setup of a Jetty Service</a></li>
</ul>
</li>
<li><a href="#startup-windows-service">Startup via Windows Service</a></li>
</ul>
</li>
<li><a href="#troubleshooting">Troubleshooting</a>
<ul class="sectlevel2">
<li><a href="#troubleshooting-zip-exceptions">Troubleshooting Zip Exceptions</a>
<ul class="sectlevel3">
<li><a href="#remedy">Remedy</a></li>
</ul>
</li>
<li><a href="#troubleshooting-locked-files-on-windows">Troubleshooting Locked Files on Windows</a>
<ul class="sectlevel3">
<li><a href="#_remedy">Remedy</a>
<ul class="sectlevel4">
<li><a href="#_using-override-web-xml">Using override-web.xml</a></li>
<li><a href="#_using-a-context-xml-file">Using a Context XML File</a></li>
<li><a href="#_using-the-jetty-maven-plugin">Using the Jetty Maven Plugin</a></li>
</ul>
</li>
<li><a href="#_alternate-remedy">Alternate Remedy</a></li>
</ul>
</li>
<li><a href="#preventing-memory-leaks">Preventing Memory Leaks</a>
<ul class="sectlevel3">
<li><a href="#preventing-webapp-classloader-pinning">Preventing WebApp Classloader Pinning</a>
<ul class="sectlevel4">
<li><a href="#preventers-table">Preventers</a></li>
<li><a href="#configuring-preventers">Configuring Preventers</a></li>
</ul>
</li>
<li><a href="#jsp-bugs">JSP Bugs: Permgen Problems</a></li>
<li><a href="#jvm-bugs">JVM Bugs</a>
<ul class="sectlevel4">
<li><a href="#jvm-garbage-collection-problems">Garbage Collection Problems</a></li>
<li><a href="#direct-byte-buffers">Direct ByteBuffers</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#troubleshooting-slow-deployment">Troubleshooting Slow Deployment</a>
<ul class="sectlevel3">
<li><a href="#_remedies">Remedies</a>
<ul class="sectlevel4">
<li><a href="#_limit-which-servletcontainerinitializers-to-execute">Limit Which ServletContainerInitializers to Execute</a></li>
<li><a href="#_limit-which-jars-to-scan">Limit Which Jars to Scan</a></li>
<li><a href="#_limit-scanning-to-first-deployment-only-quickstart">Limit Scanning to First Deployment Only (Quickstart)</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#security-reports">Jetty Security Reports</a>
<ul class="sectlevel3">
<li><a href="#_list-of-security-reports">List of Security Reports</a></li>
<li><a href="#_reporting-security-issues">Reporting Security Issues</a></li>
</ul>
</li>
<li><a href="#watchservice">Java WatchService</a>
<ul class="sectlevel3">
<li><a href="#_remedy-2">Remedy</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#optimizing">Optimizing Jetty</a>
<ul class="sectlevel2">
<li><a href="#garbage-collection">Garbage Collection</a>
<ul class="sectlevel3">
<li><a href="#garbage-collection-logging-configuration">Garbage Collection Logging Configuration</a></li>
</ul>
</li>
<li><a href="#high-load">High Load</a>
<ul class="sectlevel3">
<li><a href="#_load-generation-for-load-testing">Load Generation for Load Testing</a></li>
<li><a href="#_operating-system-tuning">Operating System Tuning</a>
<ul class="sectlevel4">
<li><a href="#_linux">Linux</a>
<ul class="sectlevel5">
<li><a href="#_tcp-buffer-sizes">TCP Buffer Sizes</a></li>
<li><a href="#_queue-sizes">Queue Sizes</a></li>
<li><a href="#_ports">Ports</a></li>
<li><a href="#_file-descriptors">File Descriptors</a></li>
<li><a href="#_congestion-control">Congestion Control</a></li>
<li><a href="#_mac-os">Mac OS</a></li>
<li><a href="#_windows">Windows</a></li>
<li><a href="#_network-tuning">Network Tuning</a></li>
<li><a href="#_jvm-tuning">JVM Tuning</a></li>
<li><a href="#_acceptors">Acceptors</a></li>
<li><a href="#_low-resource-limits">Low Resource Limits</a></li>
<li><a href="#_thread-pool">Thread Pool</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#limit-load">Limiting Load</a>
<ul class="sectlevel3">
<li><a href="#_low-resources-monitor">Low Resources Monitor</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#websocket-jetty">Jetty Websocket API</a>
<ul class="sectlevel2">
<li><a href="#websocket-jetty-server-api">Jetty WebSocket Server API</a>
<ul class="sectlevel3">
<li><a href="#_the-jetty-websocketservlet">The Jetty WebSocketServlet</a></li>
<li><a href="#_using-the-jettywebsocketcreator">Using the JettyWebSocketCreator</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#websocket-java">Java Websocket API</a></li>
</ul>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="_old-jetty-documentation"><a class="anchor" href="#_old-jetty-documentation"></a><a class="link" href="#_old-jetty-documentation">OLD JETTY DOCUMENTATION</a></h2>
<div class="sectionbody">
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The Jetty documentation that follows refers to old Jetty versions, and it is currently being ported to the current Jetty version.</p>
</div>
<div class="paragraph">
<p>Please be patient if you find incorrect documentation for the current Jetty version: eventually, the old documentation will be ported to the current Jetty version and it will be up to date.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="alpn-chapter"><a class="anchor" href="#alpn-chapter"></a><a class="link" href="#alpn-chapter">Application Layer Protocol Negotiation (ALPN)</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>The development of new web protocols such as HTTP/2 raised the need of protocol
negotiation within a Transport Layer Security (TLS) handshake.
A protocol negotiation called ALPN (Application Layer Protocol Negotiation -
<a href="https://tools.ietf.org/html/rfc7301">RFC7301</a>) has been defined to accomplish this.</p>
</div>
<div class="paragraph">
<p>ALPN has now replaced the older (and now fully deprecated) NPN in the general Web
as of 2016.</p>
</div>
<div class="paragraph">
<p>For those browsers that support HTTP/2, they all now support ALPN.
Starting with Jetty 9.3.0, only ALPN is supported by Jetty.</p>
</div>
<div class="sect2">
<h3 id="alpn"><a class="anchor" href="#alpn"></a><a class="link" href="#alpn">Introducing ALPN</a></h3>
<div class="paragraph">
<p>Application Layer Protocol Negotiation (ALPN) is a TLS extension that allows client and server to negotiate the application protocol that they will use to communicate within the encryption provided by TLS.</p>
</div>
<div class="paragraph">
<p>Any protocol can be negotiated by ALPN within a TLS connection; the protocols that are most commonly negotiated are HTTP/2 and HTTP/1.1.</p>
</div>
<div class="paragraph">
<p>Browsers only support HTTP/2 over TLS by negotiating the HTTP/2 protocol via ALPN.
You need to configure the server to support TLS and ALPN if you want browsers to use
the HTTP/2 protocol, otherwise they will default to HTTP/1.1.</p>
</div>
<div class="paragraph">
<p>In the Jetty project, ALPN is <em>used</em> in two artifacts: <code>jetty-alpn-client</code> and <code>jetty-alpn-server</code>, respectively for the client and for the server.</p>
</div>
<div class="paragraph">
<p>When using Jetty as a standalone server via the Jetty distribution, the <code>jetty-alpn-server</code> artifact is automatically included in the server classpath by the Jetty module system.</p>
</div>
<div class="paragraph">
<p>When using Jetty embedded, the <code>jetty-alpn-client</code> and <code>jetty-alpn-server</code> artifacts must be included in the classpath, respectively for client and server use cases.</p>
</div>
<div class="paragraph">
<p>The ALPN implementation is <em>provided</em> to these two artifacts with the following three options:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>For JDK 8 or later, a provider based on the <a href="#conscrypt">Conscrypt security provider</a></p>
<div class="ulist">
<ul>
<li>
<p>Works with JDK 8 or later and provides improved performance</p>
</li>
<li>
<p>Binds to the OpenSSL native library shipped by Conscrypt and is therefore only available on the platforms supported by Conscrypt</p>
</li>
</ul>
</div>
</li>
<li>
<p>For JDK 9 or later, a provider based on the ALPN APIs present in the JDK</p>
<div class="ulist">
<ul>
<li>
<p>Works with JDK 9 or later, pure Java implementation</p>
</li>
<li>
<p>Lower performance than Conscrypt</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>The first, although hosted under the umbrella of the Jetty project, is independent of Jetty (the Servlet Container); you can use it in any other Java network server.</p>
</div>
<div class="paragraph">
<p>Each provider above provides an ALPN <em>service</em> implementation; Jetty uses the <code>ServiceLoader</code> mechanism to load these service implementations.
At least one valid provider must be present in the server classpath.
For example, using JDK 8 with the JDK 9 ALPN provider is an <em>invalid</em> combination.
The absence of valid implementations is an error at startup (see also the <a href="#alpn-troubleshooting">troubleshooting section</a>).</p>
</div>
<div class="paragraph">
<p>There may be multiple ALPN service providers in the server classpath.
When a new connection is created, an <code>SSLEngine</code> instance is associated to it; each <code>SSLEngine</code> is passed all service implementations, until one accepts it.</p>
</div>
<div class="paragraph">
<p>It is therefore possible to have multiple providers active at the same time, for example the JDK 9 provider and the Conscrypt provider, and at runtime the correct one will be chosen by the Jetty runtime.</p>
</div>
<div class="sect3">
<h4 id="alpn-conscrypt"><a class="anchor" href="#alpn-conscrypt"></a><a class="link" href="#alpn-conscrypt">ALPN and Conscrypt</a></h4>
<div class="paragraph">
<p>When using JDK 8 or later, you can use the <a href="https://conscrypt.org/">Conscrypt</a> security provider to provide the ALPN service implementation.</p>
</div>
<div class="paragraph">
<p>Conscrypt binds natively to BoringSSL (a fork of OpenSSL by Google), so ALPN will be supported via the support provided by BoringSSL (bundled together with Conscrypt).</p>
</div>
<div class="paragraph">
<p>When using Jetty as a standalone server via the Jetty distribution, ALPN is enabled by enabling the <code>conscrypt</code> module.</p>
</div>
<div class="paragraph">
<p>When using Jetty embedded, ALPN is enabled by the <code>jetty-alpn-conscrypt-client</code> and <code>jetty-alpn-conscrypt-server</code> artifacts, respectively for client usage and server usage.
In addition, you also need the Conscrypt artifacts, typically the <code>org.conscrypt:conscrypt-openjdk-uber</code> artifact.
All these artifacts must be added to the classpath.</p>
</div>
</div>
<div class="sect3">
<h4 id="alpn-jdk9"><a class="anchor" href="#alpn-jdk9"></a><a class="link" href="#alpn-jdk9">ALPN and JDK 9</a></h4>
<div class="paragraph">
<p>When using JDK 9 or later and Jetty as a standalone server via the Jetty distribution, ALPN support is automatically enabled when the <code>http2</code> module is enabled.
This enables transitively the <code>alpn-9</code> module which puts the <code>jetty-alpn-java-server</code> artifact in the server classpath, providing the ALPN JDK 9 service implementation.</p>
</div>
<div class="paragraph">
<p>When using JDK 9 or later and Jetty embedded, the ALPN service implementation is provided by the <code>jetty-alpn-java-client</code> and <code>jetty-alpn-java-server</code> artifacts, respectively for client usage and server usage, and must be added to the classpath.</p>
</div>
<div class="sect4">
<h5 id="alpn-osgi"><a class="anchor" href="#alpn-osgi"></a><a class="link" href="#alpn-osgi">Starting in OSGi</a></h5>
<div class="paragraph">
<p>To use ALPN in an OSGi environment, in addition to what described above, you will also need to deploy the <code>jetty-osgi-alpn</code> jar.
This jar contains a <code>Fragment-Host</code> directive that ensures the ALPN classes will be available from the system bundle.</p>
</div>
<div class="paragraph">
<p>You can download the <a href="https://repo1.maven.org/maven2/org/eclipse/jetty/osgi/jetty-osgi-alpn/">jetty-osgi-alpn jar</a> from Maven Central.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
OSGi <strong>requires</strong> a <code>ServiceLoader</code> implementation for Jetty to function properly.
OSGi leverages <a href="http://aries.apache.org/modules/spi-fly.html">Apache Aries SPI Fly</a> for this functionality.
You can read more about OSGi and <code>ServiceLoader</code> <a href="http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html">here.</a>
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
</div>
<div class="sect3">
<h4 id="alpn-troubleshooting"><a class="anchor" href="#alpn-troubleshooting"></a><a class="link" href="#alpn-troubleshooting">ALPN Troubleshooting</a></h4>
<div class="paragraph">
<p>When starting the Jetty server, especially when using Jetty embedded, it may be possible that you see an error similar to this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">IllegalStateException: no ALPN processor</code></pre>
</div>
</div>
<div class="paragraph">
<p>The error means that you don&#8217;t have the ALPN dependencies setup correctly in your classpath.</p>
</div>
<div class="paragraph">
<p>For example, you do not have the <code>jetty-alpn-java-server</code> artifact in the classpath.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="annotations"><a class="anchor" href="#annotations"></a><a class="link" href="#annotations">Annotations</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>Jetty supports the servlet specification annotations.
It is not enable by default, so the following sections show you how to enable it, and how to use them.</p>
</div>
<div class="sect2">
<h3 id="annotations-quick-setup"><a class="anchor" href="#annotations-quick-setup"></a><a class="link" href="#annotations-quick-setup">Quick Setup</a></h3>
<div class="sect3">
<h4 id="_jetty-distribution"><a class="anchor" href="#_jetty-distribution"></a><a class="link" href="#_jetty-distribution">Jetty Distribution</a></h4>
<div class="paragraph">
<p>If you are using the jetty distribution, then annotations are enabled by default.
The annotations <a href="#startup-modules">module</a> and its transitive dependencies are responsible for making annotation processing available.</p>
</div>
<div class="paragraph">
<p>Note that annotations that relate to <a href="#jndi">JNDI</a>, such as @Resource and @Resources are enabled via the JNDI module, which is a transitive dependency on the annotations module.</p>
</div>
</div>
<div class="sect3">
<h4 id="_jetty-maven-plugin"><a class="anchor" href="#_jetty-maven-plugin"></a><a class="link" href="#_jetty-maven-plugin">Jetty Maven Plugin</a></h4>
<div class="paragraph">
<p>Annotations and JNDI are pre-enabled for the Maven plugin.</p>
</div>
</div>
<div class="sect3">
<h4 id="_embedding"><a class="anchor" href="#_embedding"></a><a class="link" href="#_embedding">Embedding</a></h4>
<div class="paragraph">
<p>To use annotations in an embedded scenario, you will need to include the <code>jetty-annotations</code> jar and all its dependencies onto your classpath.
You will also need to include the <code>org.eclipse.jetty.annotations.AnnotationConfiguration</code> class into the list of <a href="#webapp-configurations">Configuration classes</a> applied to the <code>org.eclipse.jetty.webapp.WebAppContext</code> class representing your webapp.</p>
</div>
<div class="paragraph">
<p>Below is an example application that sets up the standard <code>test-spec.war</code> webapp from the distribution in embedded fashion.
It can also be found in the Jetty GitHub repository on the examples/embedded page as <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded"><code>ServerWithAnnotations.java</code>.</a>
Note that the <code>test-spec.war</code> uses not only annotations, but also <a href="#jndi">JNDI</a>, so this example also enables their processing (via the <a href="#jndi-configuration-classes">org.eclipse.jetty.plus.webapp.EnvConfiguration</a>, <a href="#jndi-configuration-classes">org.eclipse.jetty.plus.webapp.PlusConfiguration</a> and their related jars).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in annotations/quick-annotations-setup.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Unresolved directive in annotations/chapter.adoc - include::using-annotations.adoc[]</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="using-annotations-embedded"><a class="anchor" href="#using-annotations-embedded"></a><a class="link" href="#using-annotations-embedded">Using Annotations with Jetty Embedded</a></h3>
<div class="sect3">
<h4 id="_setting-up-the-classpath"><a class="anchor" href="#_setting-up-the-classpath"></a><a class="link" href="#_setting-up-the-classpath">Setting up the Classpath</a></h4>
<div class="paragraph">
<p>You will need to place the following Jetty jar files onto the classpath of your application.
You can obtain them from the <a href="https://www.eclipse.org/jetty/download.html">Jetty distribution</a>, or the <a href="https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-annotations">Maven repository</a>:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>jetty-plus.jar
jetty-annotations.jar</pre>
</div>
</div>
<div class="paragraph">
<p>You will also need the <a href="http://asm.ow2.org/">asm</a> jar, which you can obtain from <a href="http://central.maven.org/maven2/org/eclipse/jetty/orbit/org.objectweb.asm/3.3.1.v201105211655/org.objectweb.asm-3.3.1.v201105211655.jar">this link.</a></p>
</div>
</div>
<div class="sect3">
<h4 id="_example"><a class="anchor" href="#_example"></a><a class="link" href="#_example">Example</a></h4>
<div class="paragraph">
<p>Here&#8217;s an example application that sets up a Jetty server, performs some setup to ensure that annotations are scanned, and then deploys a webapp that uses annotations.
This example also uses the @Resource annotation which involves JNDI, so we would also <a href="#jndi-embedded">add the necessary JNDI jars to the classpath</a>.
The example also adds in the configuration classes that are responsible for JNDI (see line 19).</p>
</div>
<div class="paragraph">
<p>The code is as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">org.eclipse.jetty.security.HashLoginService</span>;
<span class="keyword">import</span> <span class="include">org.eclipse.jetty.server.Server</span>;
<span class="keyword">import</span> <span class="include">org.eclipse.jetty.webapp.WebAppContext</span>;
<span class="comment">/**
* ServerWithAnnotations
*
*
*/</span>
<span class="directive">public</span> <span class="type">class</span> <span class="class">ServerWithAnnotations</span>
{
<span class="directive">public</span> <span class="directive">static</span> <span class="directive">final</span> <span class="type">void</span> main(<span class="predefined-type">String</span> args<span class="type">[]</span>) <span class="directive">throws</span> <span class="exception">Exception</span>
{
<span class="comment">//Create the server</span>
Server server = <span class="keyword">new</span> Server(<span class="integer">8080</span>);
<span class="comment">//Enable parsing of jndi-related parts of web.xml and jetty-env.xml</span>
org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addAfter(<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.FragmentConfiguration</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.webapp.EnvConfiguration</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.webapp.PlusConfiguration</span><span class="delimiter">&quot;</span></span>);
classlist.addBefore(<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.JettyWebXmlConfiguration</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.annotations.AnnotationConfiguration</span><span class="delimiter">&quot;</span></span>);
<span class="comment">//Create a WebApp</span>
WebAppContext webapp = <span class="keyword">new</span> WebAppContext();
webapp.setContextPath(<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span>);
webapp.setWar(<span class="string"><span class="delimiter">&quot;</span><span class="content">../../tests/test-webapps/test-servlet-spec/test-spec-webapp/target/test-spec-webapp-9.0.4-SNAPSHOT.war</span><span class="delimiter">&quot;</span></span>);
server.setHandler(webapp);
<span class="comment">//Register new transaction manager in JNDI</span>
<span class="comment">//At runtime, the webapp accesses this as java:comp/UserTransaction</span>
org.eclipse.jetty.plus.jndi.Transaction transactionMgr = <span class="keyword">new</span> org.eclipse.jetty.plus.jndi.Transaction(<span class="keyword">new</span> com.acme.MockUserTransaction());
<span class="comment">//Define an env entry with webapp scope.</span>
org.eclipse.jetty.plus.jndi.EnvEntry maxAmount = <span class="keyword">new</span> org.eclipse.jetty.plus.jndi.EnvEntry (webapp, <span class="string"><span class="delimiter">&quot;</span><span class="content">maxAmount</span><span class="delimiter">&quot;</span></span>, <span class="keyword">new</span> <span class="predefined-type">Double</span>(<span class="integer">100</span>), <span class="predefined-constant">true</span>);
<span class="comment">// Register a mock DataSource scoped to the webapp</span>
org.eclipse.jetty.plus.jndi.Resource mydatasource = <span class="keyword">new</span> org.eclipse.jetty.plus.jndi.Resource(webapp, <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc/mydatasource</span><span class="delimiter">&quot;</span></span>, <span class="keyword">new</span> com.acme.MockDataSource());
<span class="comment">// Configure a LoginService</span>
HashLoginService loginService = <span class="keyword">new</span> HashLoginService();
loginService.setName(<span class="string"><span class="delimiter">&quot;</span><span class="content">Test Realm</span><span class="delimiter">&quot;</span></span>);
loginService.setConfig(<span class="string"><span class="delimiter">&quot;</span><span class="content">src/test/resources/realm.properties</span><span class="delimiter">&quot;</span></span>);
server.addBean(loginService);
server.start();
server.join();
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>On line 19 the configuration classes responsible for setting up JNDI and <code>java:comp/env</code> are added.</p>
</div>
<div class="paragraph">
<p>On line 20 we add in the configuration class that ensures annotations are inspected.</p>
</div>
<div class="paragraph">
<p>On lines 30, 33 and 37 JNDI resources that we will be able to reference with @Resource annotations are configured.</p>
</div>
<div class="paragraph">
<p>With the setup above, a servlet that uses annotations and Jetty will honour the annotations when the webapp is deployed can be created:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">javax.annotation.security.DeclareRoles</span>;
<span class="keyword">import</span> <span class="include">javax.annotation.security.RunAs</span>;
<span class="keyword">import</span> <span class="include">javax.servlet.ServletConfig</span>;
<span class="keyword">import</span> <span class="include">javax.servlet.ServletException</span>;
<span class="keyword">import</span> <span class="include">javax.servlet.ServletOutputStream</span>;
<span class="keyword">import</span> <span class="include">javax.servlet.annotation.WebInitParam</span>;
<span class="keyword">import</span> <span class="include">javax.servlet.annotation.WebServlet</span>;
<span class="keyword">import</span> <span class="include">javax.servlet.http.HttpServlet</span>;
<span class="keyword">import</span> <span class="include">javax.servlet.http.HttpServletRequest</span>;
<span class="keyword">import</span> <span class="include">javax.servlet.http.HttpServletResponse</span>;
<span class="keyword">import</span> <span class="include">javax.sql.DataSource</span>;
<span class="keyword">import</span> <span class="include">javax.transaction.UserTransaction</span>;
<span class="comment">/**
* AnnotationTest
*
* Use servlet 3.0 annotations from within Jetty.
*
* Also uses servlet 2.5 resource injection and lifecycle callbacks
*/</span>
<span class="annotation">@RunAs</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">special</span><span class="delimiter">&quot;</span></span>)
<span class="annotation">@WebServlet</span>(urlPatterns = {<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">/test/*</span><span class="delimiter">&quot;</span></span>}, name=<span class="string"><span class="delimiter">&quot;</span><span class="content">AnnotationTest</span><span class="delimiter">&quot;</span></span>, initParams={<span class="annotation">@WebInitParam</span>(name=<span class="string"><span class="delimiter">&quot;</span><span class="content">fromAnnotation</span><span class="delimiter">&quot;</span></span>, value=<span class="string"><span class="delimiter">&quot;</span><span class="content">xyz</span><span class="delimiter">&quot;</span></span>)})
<span class="annotation">@DeclareRoles</span>({<span class="string"><span class="delimiter">&quot;</span><span class="content">user</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">client</span><span class="delimiter">&quot;</span></span>})
<span class="directive">public</span> <span class="type">class</span> <span class="class">AnnotationTest</span> <span class="directive">extends</span> HttpServlet
{
<span class="directive">private</span> <span class="predefined-type">DataSource</span> myDS;
<span class="annotation">@Resource</span>(mappedName=<span class="string"><span class="delimiter">&quot;</span><span class="content">UserTransaction</span><span class="delimiter">&quot;</span></span>)
<span class="directive">private</span> UserTransaction myUserTransaction;
<span class="annotation">@Resource</span>(mappedName=<span class="string"><span class="delimiter">&quot;</span><span class="content">maxAmount</span><span class="delimiter">&quot;</span></span>)
<span class="directive">private</span> <span class="predefined-type">Double</span> maxAmount;
<span class="annotation">@Resource</span>(mappedName=<span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc/mydatasource</span><span class="delimiter">&quot;</span></span>)
<span class="directive">public</span> <span class="type">void</span> setMyDatasource(<span class="predefined-type">DataSource</span> ds)
{
myDS=ds;
}
<span class="annotation">@PostConstruct</span>
<span class="directive">private</span> <span class="type">void</span> myPostConstructMethod ()
{
<span class="predefined-type">System</span>.err.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">PostConstruct called</span><span class="delimiter">&quot;</span></span>);
}
<span class="annotation">@PreDestroy</span>
<span class="directive">private</span> <span class="type">void</span> myPreDestroyMethod()
{
<span class="predefined-type">System</span>.err.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">PreDestroy called</span><span class="delimiter">&quot;</span></span>);
}
<span class="directive">public</span> <span class="type">void</span> init(ServletConfig config) <span class="directive">throws</span> ServletException
{
<span class="local-variable">super</span>.init(config);
}
<span class="directive">public</span> <span class="type">void</span> doPost(HttpServletRequest request, HttpServletResponse response) <span class="directive">throws</span> ServletException, <span class="exception">IOException</span>
{
doGet(request, response);
}
<span class="directive">public</span> <span class="type">void</span> doGet(HttpServletRequest request, HttpServletResponse response) <span class="directive">throws</span> ServletException, <span class="exception">IOException</span>
{
<span class="keyword">try</span>
{
response.setContentType(<span class="string"><span class="delimiter">&quot;</span><span class="content">text/html</span><span class="delimiter">&quot;</span></span>);
ServletOutputStream out = response.getOutputStream();
out.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">&lt;html&gt;</span><span class="delimiter">&quot;</span></span>);
out.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">&lt;body&gt;</span><span class="delimiter">&quot;</span></span>);
out.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">&lt;h1&gt;Results&lt;/h1&gt;</span><span class="delimiter">&quot;</span></span>);
out.println(myDS.toString());
out.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">&lt;br/&gt;</span><span class="delimiter">&quot;</span></span>);
out.println(maxAmount.toString());
out.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">&lt;/body&gt;</span><span class="delimiter">&quot;</span></span>);
out.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">&lt;/html&gt;</span><span class="delimiter">&quot;</span></span>);
out.flush();
}
<span class="keyword">catch</span> (<span class="exception">Exception</span> e)
{
<span class="keyword">throw</span> <span class="keyword">new</span> ServletException(e);
}
}
}</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="ant-and-jetty"><a class="anchor" href="#ant-and-jetty"></a><a class="link" href="#ant-and-jetty">Ant and Jetty</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>This chapter explains how to use Jetty with Ant and the Jetty Ant tasks.</p>
</div>
<div class="sect2">
<h3 id="jetty-ant"><a class="anchor" href="#jetty-ant"></a><a class="link" href="#jetty-ant">Ant Jetty Plugin</a></h3>
<div class="paragraph">
<p>The Ant Jetty plugin is a part of Jetty 9 under the <code>jetty-ant</code> module.
This plugin makes it possible to start a Jetty web server directly from the Ant build script, and to embed the Jetty web server inside your build process.
Its purpose is to provide almost the same functionality as the Jetty plugin for Maven: dynamic application reloading, working directly on web application sources, and tightly integrating with the build system.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-ant<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
<div class="sect3">
<h4 id="jetty-ant-preparation"><a class="anchor" href="#jetty-ant-preparation"></a><a class="link" href="#jetty-ant-preparation">Preparing Your Project</a></h4>
<div class="paragraph">
<p>To set up your project for Ant to run Jetty, you need a Jetty distribution and the jetty-ant Jar:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><a href="https://www.eclipse.org/jetty/download.html">Download</a> a Jetty distribution and unpack it in the local filesystem.</p>
</li>
<li>
<p><a href="https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-ant/">Get</a> the jetty-ant Jar.</p>
</li>
<li>
<p>Make a directory in your project called <code>jetty-lib/</code>.</p>
</li>
<li>
<p>Copy all of the Jars in your Jetty distribution&#8217;s <code>lib</code> directory, and all its subdirectories, into your new <code>jetty-lib</code> dir.
When copying the Jars, <em>don&#8217;t</em> preserve the Jetty distribution&#8217;s lib dir hierarchy – all the jars should be directly inside your ` jetty-lib` dir.</p>
</li>
<li>
<p>Also copy the jetty-ant Jar you downloaded earlier into the <code>jetty-lib</code> dir.</p>
</li>
<li>
<p>Make a directory in your project called <code>jetty-temp</code>.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Now you&#8217;re ready to edit or create your Ant <code>build.xml</code> file.</p>
</div>
</div>
<div class="sect3">
<h4 id="_preparing-the-build-xml-file"><a class="anchor" href="#_preparing-the-build-xml-file"></a><a class="link" href="#_preparing-the-build-xml-file">Preparing the <code>build.xml</code> file</a></h4>
<div class="paragraph">
<p>Begin with an empty <code>build.xml</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Add a <code>&lt;taskdef&gt;</code> that imports all available Jetty tasks:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Now you are ready to add a new target for running Jetty:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run</span> <span class="tag">/&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This is the minimal configuration you need. You can now start Jetty on the default port of 8080.</p>
</div>
</div>
<div class="sect3">
<h4 id="_starting-jetty-via-ant"><a class="anchor" href="#_starting-jetty-via-ant"></a><a class="link" href="#_starting-jetty-via-ant">Starting Jetty via Ant</a></h4>
<div class="paragraph">
<p>At the command line enter:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; ant jetty.run</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_configuring-the-jetty-container"><a class="anchor" href="#_configuring-the-jetty-container"></a><a class="link" href="#_configuring-the-jetty-container">Configuring the Jetty Container</a></h4>
<div class="paragraph">
<p>A number of configuration options can help you set up the Jetty environment so that your web application has all the resources it needs:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">ports and connectors</dt>
<dd>
<p>To configure the port that Jetty starts on you need to define a connector.
First you need to configure a <code>&lt;typedef&gt;</code> for the Connector class and then define the connector in the Jetty tags:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">connector</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.ant.types.Connector</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;connectors&gt;</span>
<span class="tag">&lt;connector</span> <span class="attribute-name">port</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">8090</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/connectors&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
You can set the port to 0, which starts the Jetty server connector on an arbitrary available port.
You can then access these values from system properties <code>jetty.ant.server.port</code> and <code>jetty.ant.server.host</code>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</dd>
<dt class="hdlist1">login services</dt>
<dd>
<p>If your web application requires authentication and authorization services, you can configure these on the Jetty container.
Here&#8217;s an example of how to set up an <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/security/HashLoginService.html">org.eclipse.jetty.security.HashLoginService</a>:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">hashLoginService</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.HashLoginService</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;loginServices&gt;</span>
<span class="tag">&lt;hashLoginService</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Test Realm</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">config</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/realm.properties</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/loginServices&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">request log</dt>
<dd>
<p>The <code>requestLog</code> option allows you to specify a request logger for the Jetty instance.
You can either use the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/NCSARequestLog.html">org.eclipse.jetty.server.NCSARequestLog</a> class, or supply the name of your custom class:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run</span> <span class="attribute-name">requestLog</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.acme.MyFancyRequestLog</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">temporary directory</dt>
<dd>
<p>You can configure a directory as a temporary file store for uses such as expanding files and compiling JSPs by supplying the <code>tempDirectory</code> option:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run</span> <span class="attribute-name">tempDirectory</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/jetty-temp</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">other context handlers</dt>
<dd>
<p>You may need to configure some other context handlers to run at the same time as your web application.
You can specify these other context handlers using the <code>&lt;contextHandlers&gt;</code> element.
You need to supply a <code>&lt;typedef&gt;</code> for it before you can use it:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextHandlers</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.ant.types.ContextHandlers</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;contextHandlers&gt;</span>
<span class="tag">&lt;contextHandler</span> <span class="attribute-name">resourceBase</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/stuff</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextPath</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">/stuff</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/contextHandlers&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">system properties</dt>
<dd>
<p>As a convenience, you can configure system properties by using the <code>&lt;systemProperties&gt;</code> element.
Be aware that, depending on the purpose of the system property, setting it from within the Ant execution may mean that it is evaluated too late, as the JVM evaluates some system properties on entry.</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;systemProperties&gt;</span>
<span class="tag">&lt;systemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">foo</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">bar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/systemProperties&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">jetty XML file</dt>
<dd>
<p>If you have a lot of configuration to apply to the Jetty container, it can be more convenient to put it into a standard Jetty XML configuration file and have the Ant plugin apply it before starting Jetty:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run</span> <span class="attribute-name">jettyXml</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/jetty.xml</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">scanning for changes</dt>
<dd>
<p>The most useful mode in which to run the Ant plugin is for it to continue to execute Jetty and automatically restart your web application if any part of it changes (for example, your IDE
recompiles the classes of the web application).
The <code>scanIntervalSeconds</code> option controls how frequently the <code>&lt;jetty.run&gt;</code> task scans your web application/WAR file for changes.
The default value of <code>0</code> disables scanning. Here&#8217;s an example where Jetty checks for changes every five seconds:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run</span> <span class="attribute-name">scanIntervalSeconds</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">5</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">stopping</dt>
<dd>
<p>In normal mode (<code>daemon="false"</code>), the <code>&lt;jetty.run&gt;</code> task runs until you <code>cntrl-c</code> it. It may be useful to script both the stop AND the start of Jetty.
For such a case, we provide the <code>&lt;jetty.stop&gt;</code> task.
+
To use it, you need to provide a port and an identifying string to both the ` &lt;jetty.run&gt;` and the <code>&lt;jetty.stop&gt;</code> tasks, where <code>&lt;jetty.run&gt;</code> listens on the given port for a stop message containing the given string, and cleanly stops Jetty when it is received.
The <code>&lt;jetty.stop&gt;</code> task sends this stop message.
You can also optionally provide a <code>stopWait</code> value (in seconds), which is the length of time the <code>&lt;jetty.stop&gt;</code> task waits for confirmation that the stop succeeded:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run</span> <span class="attribute-name">stopPort</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">9999</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">stopKey</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">9999</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.stop</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.stop</span> <span class="attribute-name">stopPort</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">9999</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">stopKey</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">9999</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">stopWait</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">10</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>To stop jetty via Ant, enter:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; ant jetty.stop</code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">execution without pausing ant</dt>
<dd>
<p>Usually, the <code>&lt;jetty.run&gt;</code> task runs until you <code>cntrl-c</code> it, pausing the execution of Ant as it does so. In some cases, it may be useful to let Ant continue executing.
For example, to run your unit tests you may need other tasks to execute while Jetty is running.
For this case, we provide the <code>daemon</code> option.
This defaults to <code>false</code>. For <code>true</code>, Ant continues to execute after starting Jetty.
If Ant exits, so does Jetty. Understand that this option does <em>not</em> fork a new process for Jetty.</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run</span> <span class="attribute-name">daemon</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">true</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="_deploying-a-web-application"><a class="anchor" href="#_deploying-a-web-application"></a><a class="link" href="#_deploying-a-web-application">Deploying a Web Application</a></h4>
<div class="paragraph">
<p>Add a <code>&lt;typedef&gt;</code> for the <code>org.eclipse.jetty.ant.AntWebAppContext</code> class with name <em>webApp</em>, then add a <code>&lt;webApp&gt;</code> element to <code>&lt;jetty.run&gt;</code> to describe your web application.
The following example deploys a web application that is expanded in the local directory <code>foo/</code> to context path ` / `:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">webApp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.ant.AntWebAppContext</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;webApp</span> <span class="attribute-name">war</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/foo</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextPath</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">deploying a WAR file</dt>
<dd>
<p>It is not necessary to expand the web application into a directory.
It is fine to deploy it as a WAR file:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">webApp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.ant.AntWebAppContext</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;webApp</span> <span class="attribute-name">war</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/foo.war</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextPath</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">deploying more than one web application</dt>
<dd>
<p>You can also deploy more than one web application:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">webApp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.ant.AntWebAppContext</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;webApp</span> <span class="attribute-name">war</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/foo.war</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextPath</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;webApp</span> <span class="attribute-name">war</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/other contextPath=</span><span class="delimiter">&quot;</span></span><span class="error">/</span><span class="attribute-name">other</span><span class="error">&quot;</span><span class="tag">/&gt;</span>
<span class="tag">&lt;webApp</span> <span class="attribute-name">war</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/bar.war</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextPath</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">/bar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
</dl>
</div>
<div class="sect4">
<h5 id="_configuring-the-web-application"><a class="anchor" href="#_configuring-the-web-application"></a><a class="link" href="#_configuring-the-web-application">Configuring the Web Application</a></h5>
<div class="paragraph">
<p>As the <code>org.eclipse.jetty.ant.AntWebAppContext</code> class is an extension of
the
<a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html"><code>org.eclipse.jetty.webapp.WebAppContext</code></a>
class, you can configure it by adding attributes of the same name
(without the <code>set</code> or <code>add</code> prefix) as the setter methods.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example that specifies the location of the <code>web.xml</code> file (equivalent to method <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setDescriptor%28java.lang.String%29"><code>AntWebAppContext.setDescriptor()</code></a>) and the web application&#8217;s temporary directory (equivalent to method <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setTempDirectory%28java.io.File%29"><code>AntWebAppContext.setTempDirectory()</code></a>):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">webApp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.ant.AntWebAppContext</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;webApp</span> <span class="attribute-name">descriptor</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/web.xml</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">tempDirectory</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/my-temp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">war</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/foo</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextPath</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Other extra configuration options for the AntWebAppContext include:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">extra classes and Jars</dt>
<dd>
<p>If your web application&#8217;s classes and Jars do not reside inside <code>WEB-INF</code> of the resource base directory, you can use the &lt;classes&gt; and &lt;jar&gt; elements to tell Ant where to find them. Here&#8217;s an example:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">webApp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.ant.AntWebAppContext</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;webApp</span> <span class="attribute-name">descriptor</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/web.xml</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">tempDirectory</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/my-temp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">war</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/foo</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextPath</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;classes</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/classes</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;include</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">**/*.class</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;include</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">**/*.properties</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/classes&gt;</span>
<span class="tag">&lt;lib</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/jars</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;include</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">**/*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;exclude</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">**/*.dll</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/lib&gt;</span>
<span class="tag">&lt;/webApp&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">context attributes</dt>
<dd>
<p>Jetty allows you to set up ServletContext attributes on your web application.
You configure them in a context XML file that is applied to your WebAppContext instance prior to starting it.
For convenience, the Ant plugin permits you to configure these directly in the build file.
Here&#8217;s an example:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">webApp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.ant.AntWebAppContext</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;webApp</span> <span class="attribute-name">war</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/foo</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextPath</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;attributes&gt;</span>
<span class="tag">&lt;attribute</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">my.param</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">123</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/attributes&gt;</span>
<span class="tag">&lt;/webApp&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1"><code>jetty-env.xml</code> file</dt>
<dd>
<p>If you are using features such as <a href="#configuring_jndi">JNDI</a> with your web application, you may need to configure a <a href="#using_jndi"><code>WEB-INF/jetty-env.xml</code></a> file to define resources. If the structure of your web application project is such that the source of <code>jetty-env.xml</code> file resides somewhere other than <code>WEB-INF</code>, you can use the <code>jettyEnvXml</code> attribute to tell Ant where to find it:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-Ant integration test</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">basedir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">webApp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.ant.AntWebAppContext</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;webApp</span> <span class="attribute-name">war</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/foo</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextPath</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">jettyEnvXml</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/jetty-env.xml</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;attributes&gt;</span>
<span class="tag">&lt;/webApp&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">context XML file</dt>
<dd>
<p>You may prefer or even require to do some advanced configuration of your web application outside of the Ant build file.
In this case, you can use a standard context XML configuration file which the Ant plugin applies to your web application before it is deployed.
Be aware that the settings from the context XML file <em>override</em> those of the attributes and nested elements you defined in the build file.</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml">project name=&quot;Jetty-Ant integration test&quot; basedir=&quot;.&quot;<span class="error">&gt;</span>
<span class="tag">&lt;path</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;fileset</span> <span class="attribute-name">dir</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty-lib</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">includes</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">*.jar</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/path&gt;</span>
<span class="tag">&lt;taskdef</span> <span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">resource</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tasks.properties</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;typedef</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">webApp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">classname</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.ant.AntWebAppContext</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">classpathref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.plugin.classpath</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">loaderref</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.loader</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;target</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.run</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;jetty.run&gt;</span>
<span class="tag">&lt;webApp</span> <span class="attribute-name">war</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/foo</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextPath</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">contextXml</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${basedir}/jetty-env.xml</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;attributes&gt;</span>
<span class="tag">&lt;/webApp&gt;</span>
<span class="tag">&lt;/jetty.run&gt;</span>
<span class="tag">&lt;/target&gt;</span>
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</dd>
</dl>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="architecture"><a class="anchor" href="#architecture"></a><a class="link" href="#architecture">Architecture</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>General items related to the architecture of jetty and how it deals with certain design decisions.</p>
</div>
<div class="sect2">
<h3 id="jetty-classloading"><a class="anchor" href="#jetty-classloading"></a><a class="link" href="#jetty-classloading">Jetty Classloading</a></h3>
<div class="paragraph">
<p>Class loading in a web container is slightly more complex than a normal Java application.
The normal configuration is that each web context (web application or WAR file) has its own classloader, which has the system classloader as its parent.
Such a classloader hierarchy is normal in Java, however the servlet specification complicates the hierarchy because it requires the following:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Classes contained within <code>WEB-INF/lib</code> or <code>WEB-INF/classes</code> have priority over classes on the parent classloader.
This is the opposite of the normal behavior of a Java 2 classloader.</p>
</li>
<li>
<p>System classes such as <code>java.lang.String</code> are excluded from the webapp priority, and you may not replace them with classes in <code>WEB-INF/lib</code> or <code>WEB-INF/</code> classes.
Unfortunately the specification does not clearly state what classes are <em>System</em> classes, and it is unclear if all <code>javax</code> classes should be treated as System classes.</p>
</li>
<li>
<p>Server implementation classes like <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/Server.html">Server</a> should be hidden from the web application and should not be available in any classloader.
Unfortunately the specification does not state what classes are <em>Server</em> classes, and it is unclear if common libraries like the Xerces parser should be treated as Implementation classes.</p>
</li>
</ul>
</div>
<div class="sect3">
<h4 id="configuring-webapp-classloading"><a class="anchor" href="#configuring-webapp-classloading"></a><a class="link" href="#configuring-webapp-classloading">Configuring Webapp Classloading</a></h4>
<div class="paragraph">
<p>Jetty provides configuration options to control the three webapp class loading issues identified above.</p>
</div>
<div class="paragraph">
<p>You can configure webapp classloading by several methods on the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html">WebAppContext</a>.
You can call these methods directly if you are working with the Jetty API, or you can inject methods from a context XML file if you are using the Context Provider (<a href="#using-context-provider">[using-context-provider]</a>).
You CANNOT set these methods from a <code>jetty-web.xml</code> file, as it executes after the classloader configuration is set.
As a note, <code>jetty-web.xml</code> uses the webapp classpath and not the classpath of the server.</p>
</div>
<div class="sect4">
<h5 id="controlling-webapp-classloader-priority"><a class="anchor" href="#controlling-webapp-classloader-priority"></a><a class="link" href="#controlling-webapp-classloader-priority">Controlling Webapp Classloader Priority</a></h5>
<div class="paragraph">
<p>The method <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#isParentLoaderPriority()">org.eclipse.jett .webapp.WebAppContext.setParentLoaderPriority(boolean)</a> allows control over the priority given to webapp classes over system classes.
If you set it to false (the default), Jetty uses standard webapp classloading priority.
However, if in this mode some classes that are dependencies of other classes are loaded from the parent classloader (due to settings of system classes below), ambiguities might arise as both the webapp and system classloader versions can end up being loaded.</p>
</div>
<div class="paragraph">
<p>If set to true, Jetty uses normal JavaSE classloading priority, and gives priority to the parent/system classloader.
This avoids the issues of multiple versions of a class within a webapp, but the version the parent/system loader provides must be the right version for all webapps you configure in this way.</p>
</div>
</div>
<div class="sect4">
<h5 id="configuring-webapp-caching"><a class="anchor" href="#configuring-webapp-caching"></a><a class="link" href="#configuring-webapp-caching">Configuring Webapp Classloader Caching</a></h5>
<div class="paragraph">
<p>Introduced in Jetty 9.3.6, the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/CachingWebAppClassLoader.html">CachingWebAppClassLoader</a> can be used to cache <code>getResource(String)</code> results.
For webapps that search for classes and resources regularly, this can increase speed and performance.
This is an optional feature and it should be noted that it can conflict with several other libraries such as JSP, JSTL, JSF and CDI.
As such, this feature must be manually enabled for each webapp you want to use it in.</p>
</div>
<div class="paragraph">
<p>Below is an example of implementing this feature using Jetty IoC XML format:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">mywebapp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">classLoader</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.CachingWebAppClassLoader</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">mywebapp</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
...
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="classloading-setting-system-classes"><a class="anchor" href="#classloading-setting-system-classes"></a><a class="link" href="#classloading-setting-system-classes">Setting System Classes</a></h5>
<div class="paragraph">
<p>You can call the methods
<a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setSystemClasses%28java.lang.String%5B%5D%29">WebAppContext.setSystemClasses(String[])</a>
or
<a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#getSystemClasspathPattern()">WebAppContext.getSystemClasspathPattern().add(String)</a>
to allow fine control over which classes are considered system classes.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A web application can see a System class.</p>
</li>
<li>
<p>A WEB-INF class cannot replace a System class.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The default system classes are:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 1. Default System Classes</caption>
<colgroup>
<col style="width: 8%;">
<col style="width: 92%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">System Classes</th>
<th class="tableblock halign-left valign-top">Note</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">java.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java SE classes (per servlet spec v2.5 / SRV.9.7.2).</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">javax.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java SE classes (per servlet spec v2.5 / SRV.9.7.2).</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.xml.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Needed by javax.xml.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.w3c.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Needed by javax.xml.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.continuation.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Webapp can see and not change continuation classes.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.jndi.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Webapp can see and not change naming classes.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.jaas.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Webapp can see and not change JAAS classes.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.websocket.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">WebSocket is a Jetty extension.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.servlet.DefaultServlet</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Webapp can see and not change default servlet.</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>Absolute classname can be passed, names ending with <code>.</code> are treated as packages names, and names starting with <code>-</code> are treated as negative matches and must be listed before any enclosing packages.</p>
</div>
</div>
<div class="sect4">
<h5 id="setting-server-classes"><a class="anchor" href="#setting-server-classes"></a><a class="link" href="#setting-server-classes">Setting Server Classes</a></h5>
<div class="paragraph">
<p>You can call the methods <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setServerClasses%28java.lang.String%5B%5D%29">org.eclipse.jetty.webapp.WebAppContext.setServerClasses(String Array)</a> or
<a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#addServerClass(java.lang.String)">org.eclipse.jetty.webapp.WebAppContext.addServerClass(String)</a> to allow fine control over which classes are considered Server classes.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A web application cannot see a Server class.</p>
</li>
<li>
<p>A WEB-INF class can replace a Server class.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The default server classes are:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 2. Default Server Classes</caption>
<colgroup>
<col style="width: 8%;">
<col style="width: 92%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Server Classes</th>
<th class="tableblock halign-left valign-top">-org.eclipse.jetty.continuation.</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Don&#8217;t hide continuation classes.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-org.eclipse.jetty.jndi.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Don&#8217;t hide naming classes.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-org.eclipse.jetty.jaas.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Don&#8217;t hide jaas classes.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-org.eclipse.jetty.servlets.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Don&#8217;t hide utility servlet classes if provided.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-org.eclipse.jetty.servlet.DefaultServlet</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Don&#8217;t hide default servlet.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-org.eclipse.jetty.servlet.listener.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Don&#8217;t hide utility listeners</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-org.eclipse.jetty.websocket.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Don&#8217;t hide websocket extension.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="sect3">
<h4 id="adding-extra-classpaths"><a class="anchor" href="#adding-extra-classpaths"></a><a class="link" href="#adding-extra-classpaths">Adding Extra Classpaths to Jetty</a></h4>
<div class="paragraph">
<p>You can add extra classpaths to Jetty in several ways.</p>
</div>
<div class="sect4">
<h5 id="classpaths-using-start-jar"><a class="anchor" href="#classpaths-using-start-jar"></a><a class="link" href="#classpaths-using-start-jar">Using <code>start.jar</code></a></h5>
<div class="paragraph">
<p>If you are using <code>start.jar</code> via the Jetty distribution, at startup the Jetty runtime automatically loads option Jars from the top level <code>$jetty.home/lib</code> directory. The default settings include:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Adding Jars under <code>$jetty.home/lib/ext</code> to the system classpath.
You can place additional Jars here.</p>
</li>
<li>
<p>Adding the directory <code>$jetty.home/resources</code> to the classpath (may contain classes or other resources).</p>
</li>
<li>
<p>Adding a single path defined by the command line parameter <em>path</em>.</p>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="using-extra-classpath-method"><a class="anchor" href="#using-extra-classpath-method"></a><a class="link" href="#using-extra-classpath-method">Using the extraClasspath() method</a></h5>
<div class="paragraph">
<p>You can add an additional classpath to a context classloader by calling <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setExtraClasspath(java.lang.String)">org.eclipse.jetty.webapp.WebAppContext.setExtraClasspath(String)</a> with a comma-separated list of paths.
You can do so directly to the API via a context XML file such as the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">extraClasspath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>../my/classes,../my/jars/special.jar,../my/jars/other.jar<span class="tag">&lt;/Set&gt;</span>
...</code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="using-custom-webappclassloader"><a class="anchor" href="#using-custom-webappclassloader"></a><a class="link" href="#using-custom-webappclassloader">Using a Custom WebAppClassLoader</a></h4>
<div class="paragraph">
<p>If none of the alternatives already described meet your needs, you can always provide a custom classloader for your webapp.
We recommend, but do not require, that your custom loader subclasses <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppClassLoader.html">WebAppClassLoader</a>.</p>
</div>
<div class="paragraph">
<p>If you do not subclass WebAppClassLoader, we recommend that you implement the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/util/ClassVisibilityChecker.html">ClassVisibilityChecker</a> interface.
Without this interface, session persistence will be slower.</p>
</div>
<div class="paragraph">
<p>You configure the classloader for the webapp like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">MyCleverClassLoader myCleverClassLoader = <span class="keyword">new</span> MyCleverClassLoader();
...
WebAppContext webapp = <span class="keyword">new</span> WebAppContext();
...
webapp.setClassLoader(myCleverClassLoader);</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can also accomplish this in a context xml file.</p>
</div>
</div>
<div class="sect3">
<h4 id="starting-jetty-custom-classloader"><a class="anchor" href="#starting-jetty-custom-classloader"></a><a class="link" href="#starting-jetty-custom-classloader">Starting Jetty with a Custom ClassLoader</a></h4>
<div class="paragraph">
<p>If you start a Jetty server using a custom class loader–consider the Jetty classes not being available to the system class loader, only your custom class loader–you may run into class loading issues when the <code>WebAppClassLoader</code> kicks in.
By default the <code>WebAppClassLoader</code> uses the system class loader as its parent, hence the problem. This is easy to fix, like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">context.setClassLoader(<span class="keyword">new</span> WebAppClassLoader(<span class="local-variable">this</span>.getClass().getClassLoader(), context));</code></pre>
</div>
</div>
<div class="paragraph">
<p>or</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">context.setClassLoader(<span class="keyword">new</span> WebAppClassLoader(<span class="keyword">new</span> MyCustomClassLoader(), context));</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="configuring-connectors"><a class="anchor" href="#configuring-connectors"></a><a class="link" href="#configuring-connectors">Configuring Jetty Connectors</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>This chapter discusses various options for configuring Jetty connectors.</p>
</div>
<div class="sect2">
<h3 id="jetty-connectors"><a class="anchor" href="#jetty-connectors"></a><a class="link" href="#jetty-connectors">Connector Configuration Overview</a></h3>
<div class="paragraph">
<p>Connectors are the mechanism through which Jetty accepts network connections for various protocols.
Configuring a connector is a combination of configuring the following:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Network parameters on the connector itself (for example: the listening port).</p>
</li>
<li>
<p>Services the connector uses (for example: executors, schedulers).</p>
</li>
<li>
<p>Connection factories that instantiate and configure the protocol for an accepted connection.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Typically connectors require very little configuration aside from setting the listening port, and enabling <code>X-Forwarded-For</code> customization when applicable.
Additional settings, including construction your own constructor Jetty XML files, are for expert configuration only.</p>
</div>
<div class="sect3">
<h4 id="_enabling-connectors"><a class="anchor" href="#_enabling-connectors"></a><a class="link" href="#_enabling-connectors">Enabling Connectors</a></h4>
<div class="paragraph">
<p>Out of the box, Jetty provides several <a href="#startup-modules">modules</a> for enabling different types of connectors, from HTTP to HTTPS, HTTP/2, and others.
If you startup Jetty with the <code>--list-modules=connector</code> command, you can see a list of all available connector modules:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --list-modules=connector
Available Modules:
==================
tags: [connector]
Modules for tag 'connector':
----------------------------
Module: acceptratelimit
: Enable a server wide accept rate limit
Tags: connector
Depend: server
XML: etc/jetty-acceptratelimit.xml
Module: connectionlimit
: Enable a server wide connection limit
Tags: connector
Depend: server
XML: etc/jetty-connectionlimit.xml
Module: http
: Enables a HTTP connector on the server.
: By default HTTP/1 is support, but HTTP2C can
: be added to the connector with the http2c module.
Tags: connector, http
Depend: server
XML: etc/jetty-http.xml
Module: http-forwarded
: Adds a forwarded request customizer to the HTTP Connector
: to process forwarded-for style headers from a proxy.
Tags: connector
Depend: http
XML: etc/jetty-http-forwarded.xml
Module: http2
: Enables HTTP2 protocol support on the TLS(SSL) Connector,
: using the ALPN extension to select which protocol to use.
Tags: connector, http2, http, ssl
Depend: ssl, alpn
LIB: lib/http2/*.jar
XML: etc/jetty-http2.xml
Module: http2c
: Enables the HTTP2C protocol on the HTTP Connector
: The connector will accept both HTTP/1 and HTTP/2 connections.
Tags: connector, http2, http
Depend: http
LIB: lib/http2/*.jar
XML: etc/jetty-http2c.xml
Module: https
: Adds HTTPS protocol support to the TLS(SSL) Connector
Tags: connector, https, http, ssl
Depend: ssl
Optional: http-forwarded, http2
XML: etc/jetty-https.xml
Module: proxy-protocol-ssl
: Enables the Proxy Protocol on the TLS(SSL) Connector.
: http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt
: This allows a Proxy operating in TCP mode to transport
: details of the proxied connection to the server.
: Both V1 and V2 versions of the protocol are supported.
Tags: connector, ssl
Depend: ssl
XML: etc/jetty-proxy-protocol-ssl.xml
Module: ssl
: Enables a TLS(SSL) Connector on the server.
: This may be used for HTTPS and/or HTTP2 by enabling
: the associated support modules.
Tags: connector, ssl
Depend: server
XML: etc/jetty-ssl.xml
XML: etc/jetty-ssl-context.xml
Module: unixsocket
: Enables a Unix Domain Socket Connector that can receive
: requests from a local proxy and/or SSL offloader (eg haproxy) in either
: HTTP or TCP mode. Unix Domain Sockets are more efficient than
: localhost TCP/IP connections as they reduce data copies, avoid
: needless fragmentation and have better dispatch behaviours.
: When enabled with corresponding support modules, the connector can
: accept HTTP, HTTPS or HTTP2C traffic.
Tags: connector
Depend: server
LIB: lib/jetty-unixsocket-${jetty.version}.jar
LIB: lib/jnr/*.jar
XML: etc/jetty-unixsocket.xml
Module: unixsocket-forwarded
: Adds a forwarded request customizer to the HTTP configuration used
: by the Unix Domain Socket connector, for use when behind a proxy operating
: in HTTP mode that adds forwarded-for style HTTP headers. Typically this
: is an alternate to the Proxy Protocol used mostly for TCP mode.
Tags: connector
Depend: unixsocket-http
XML: etc/jetty-unixsocket-forwarded.xml
Module: unixsocket-http
: Adds a HTTP protocol support to the Unix Domain Socket connector.
: It should be used when a proxy is forwarding either HTTP or decrypted
: HTTPS traffic to the connector and may be used with the
: unix-socket-http2c modules to upgrade to HTTP/2.
Tags: connector, http
Depend: unixsocket
XML: etc/jetty-unixsocket-http.xml
Module: unixsocket-http2c
: Adds a HTTP2C connetion factory to the Unix Domain Socket Connector
: It can be used when either the proxy forwards direct
: HTTP/2C (unecrypted) or decrypted HTTP/2 traffic.
Tags: connector, http2
Depend: unixsocket-http
LIB: lib/http2/*.jar
XML: etc/jetty-unixsocket-http2c.xml
Module: unixsocket-proxy-protocol
: Enables the proxy protocol on the Unix Domain Socket Connector
: http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt
: This allows information about the proxied connection to be
: efficiently forwarded as the connection is accepted.
: Both V1 and V2 versions of the protocol are supported and any
: SSL properties may be interpreted by the unixsocket-secure
: module to indicate secure HTTPS traffic. Typically this
: is an alternate to the forwarded module.
Tags: connector
Depend: unixsocket
XML: etc/jetty-unixsocket-proxy-protocol.xml
Module: unixsocket-secure
: Enable a secure request customizer on the HTTP Configuration
: used by the Unix Domain Socket Connector.
: This looks for a secure scheme transported either by the
: unixsocket-forwarded, unixsocket-proxy-protocol or in a
: HTTP2 request.
Tags: connector
Depend: unixsocket-http
XML: etc/jetty-unixsocket-secure.xml
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>To enable a connector, simply activate the associated module.
Below is an example of activating both the <code>http</code> and <code>https</code> modules in a fresh <a href="#startup-base-and-home">Jetty base</a> using the <a href="#start-vs-startd">start.d directory</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[mybase] java -jar $JETTY_HOME/start.jar --create-startd
MKDIR : ${jetty.base}/start.d
INFO : Base directory was modified
[mybase] java -jar $JETTY_HOME/start.jar --add-to-start=http,https
INFO : server transitively enabled, ini template available with --add-to-start=server
INFO : http initialized in ${jetty.base}/start.d/http.ini
INFO : https initialized in ${jetty.base}/start.d/https.ini
INFO : ssl transitively enabled, ini template available with --add-to-start=ssl
MKDIR : ${jetty.base}/etc
COPY : ${jetty.home}/modules/ssl/keystore to ${jetty.base}/etc/keystore
INFO : Base directory was modified
[mybase] tree
.
├── etc
│   └── keystore
└── start.d
├── http.ini
└── https.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>When the <code>http</code> and <code>https</code> modules were activated, so too were any modules they were dependent on, in this case <code>server</code> and <code>ssl</code>, as well as any dependencies for those modules, such as the <code>etc</code> and <code>ketystore</code> directories for <code>ssl</code>.</p>
</div>
<div class="paragraph">
<p>At this point the server has been configured with connectors for both HTTP and HTTPS and can be started:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[mybase] java -jar $JETTY_HOME/start.jar
2017-08-31 10:19:58.855:INFO::main: Logging initialized @372ms to org.eclipse.jetty.util.log.StdErrLog
2017-08-31 10:19:59.076:INFO:oejs.Server:main: jetty-10.0.10
2017-08-31 10:19:59.125:INFO:oejs.AbstractConnector:main: Started ServerConnector@421e98e0{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2017-08-31 10:19:59.150:INFO:oejus.SslContextFactory:main: x509=X509@5315b42e(jetty,h=[jetty.eclipse.org],w=[]) for SslContextFactory@2ef9b8bc(file:///var/my-jetty-base/etc/keystore,file:///var/my-jetty-base/etc/keystore)
2017-08-31 10:19:59.151:INFO:oejus.SslContextFactory:main: x509=X509@5d624da6(mykey,h=[],w=[]) for SslContextFactory@2ef9b8bc(file:///var/my-jetty-base/etc/keystore,file:///var/my-jetty-base/etc/keystore)
2017-08-31 10:19:59.273:INFO:oejs.AbstractConnector:main: Started ServerConnector@2b98378d{SSL,[ssl, http/1.1]}{0.0.0.0:8443}
2017-08-31 10:19:59.274:INFO:oejs.Server:main: Started @791ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>When modules are enabled, they are loaded with several default options.
These can be changed by editing the associated module ini file in the <code>start.d</code> directory (or the associated lines in <code>server.ini</code> if your implementation does not use <code>start.d</code>).
For example, if we examine the <code>http.ini</code> file in our <code>start.d</code> directory created above, we will see the following settings:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># ---------------------------------------
# Module: http
# Enables a HTTP connector on the server.
# By default HTTP/1 is support, but HTTP2C can
# be added to the connector with the http2c module.
# ---------------------------------------
--module=http
### HTTP Connector Configuration
## Connector host/address to bind to
# jetty.http.host=0.0.0.0
## Connector port to listen on
# jetty.http.port=8080
## Connector idle timeout in milliseconds
# jetty.http.idleTimeout=30000
## Number of acceptors (-1 picks default based on number of cores)
# jetty.http.acceptors=-1
## Number of selectors (-1 picks default based on number of cores)
# jetty.http.selectors=-1
## ServerSocketChannel backlog (0 picks platform default)
# jetty.http.acceptQueueSize=0
## Thread priority delta to give to acceptor threads
# jetty.http.acceptorPriorityDelta=0
## HTTP Compliance: RFC7230, RFC2616, LEGACY
# jetty.http.compliance=RFC7230</code></pre>
</div>
</div>
<div class="paragraph">
<p>To make a change to these settings, uncomment the line (by removing the #) and change the property to the desired value.
For example, if you wanted to change the HTTP port to 5231, you would edit the line as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">...
## Connector port to listen on
jetty.http.port=5231
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now when the server is started, HTTP connections will enter on port 5231:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar
2017-08-31 10:31:32.955:INFO::main: Logging initialized @366ms to org.eclipse.jetty.util.log.StdErrLog
2017-08-31 10:31:33.109:INFO:oejs.Server:main: jetty-10.0.10
2017-08-31 10:31:33.146:INFO:oejs.AbstractConnector:main: Started ServerConnector@2ef9b8bc{HTTP/1.1,[http/1.1]}{0.0.0.0:5231}
...
2017-08-31 10:31:33.263:INFO:oejs.Server:main: Started @675ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>Every module has their own set of configuration options, and reviewing them all is recommended.
For additional information on the module system, please refer to our documentation on <a href="#startup-modules">Startup Modules</a>.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Editing these module files is the recommended way to edit the configuration of your server.
Making changes to the associated Jetty XML file for connectors is <strong>not</strong> recommended, and is for advanced users only.
If you do wish to edit Jetty XML, please see our section on managing <a href="#">Jetty Home and Jetty Base</a> to ensure your Jetty Home remains a standard of truth for your implementation.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="_limiting-connections"><a class="anchor" href="#_limiting-connections"></a><a class="link" href="#_limiting-connections">Limiting Connections</a></h4>
<div class="paragraph">
<p>Jetty also provides the means by which to limit connections to the server and/or contexts.
This is provided by two different modules in the distribution.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>connectionlimit</code></dt>
<dd>
<p>Applies a limit to the number of connections.
If this limit is exceeded, new connections are suspended for the time specified (in milliseconds).</p>
</dd>
<dt class="hdlist1"><code>acceptratelimit</code></dt>
<dd>
<p>Limits the rate at which new connections are accepted.
If this limit is exceeded, new connections are suspended for the time specified (in milliseconds).</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>As with the modules listed above, these can be enabled by adding <code>--add-to-start=&lt;module-name&gt;</code> to the command line.</p>
</div>
</div>
<div class="sect3">
<h4 id="_advanced-configuration"><a class="anchor" href="#_advanced-configuration"></a><a class="link" href="#_advanced-configuration">Advanced Configuration</a></h4>
<div class="paragraph">
<p>Jetty primarily uses a single connector type called <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html">ServerConnector</a>.</p>
</div>
<div class="paragraph">
<p>Prior to Jetty 9, the type of the connector specified both the protocol and the implementation used; for example, selector-based non blocking I/O vs blocking I/O, or SSL connector vs non-SSL connector.
Jetty 9 has a single selector-based non-blocking I/O connector, and a collection of <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ConnectionFactory.html"><code>ConnectionFactories</code></a> now configure the protocol on the connector.</p>
</div>
<div class="paragraph">
<p>The standard Jetty distribution comes with the following Jetty XML files that create and configure connectors; you should examine them as you read this section:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-http.xml"><code>jetty-http.xml</code></a></dt>
<dd>
<p>Instantiates a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html"><code>ServerConnector</code></a> that accepts HTTP connections (that may be upgraded to WebSocket connections).</p>
</dd>
<dt class="hdlist1"><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-ssl.xml"><code>jetty-ssl.xml</code></a></dt>
<dd>
<p>Instantiates a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html"><code>ServerConnector</code></a> that accepts SSL/TLS connections.
On it&#8217;s own, this connector is not functional and requires one or more of the following files to also be configured to add <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ConnectionFactory.html"><code>ConnectionFactories</code></a> to make the connector functional.</p>
</dd>
<dt class="hdlist1"><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-https.xml"><code>jetty-https.xml</code></a></dt>
<dd>
<p>Adds a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/HttpConnectionFactory.html"><code>HttpConnectionFactory</code></a> to the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html"><code>ServerConnector</code></a> configured by <code>jetty-ssl.xml</code> which combine to provide support for HTTPS.</p>
</dd>
<dt class="hdlist1"><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-http-forwarded.xml"><code>jetty-http-forwarded.xml</code></a></dt>
<dd>
<p>Adds a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ForwardedRequestCustomizer.html"><code>ForwardedRequestCustomizer</code></a>to the HTTP Connector to process forwarded-for style headers from a proxy.</p>
</dd>
<dt class="hdlist1"><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-http2/http2-server/src/main/config/etc/jetty-http2.xml"><code>jetty-http2.xml</code></a></dt>
<dd>
<p>Adds a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/http2/server/HTTP2ServerConnectionFactory.html"><code>Http2ServerConnectionFactory</code></a> to the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html"><code>ServerConnector</code></a> configured by <code>jetty-ssl.xml</code> to support the http2 protocol.</p>
</dd>
<dt class="hdlist1"><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-alpn/jetty-alpn-server/src/main/config/etc/jetty-alpn.xml"><code>jetty-alpn.xml</code></a></dt>
<dd>
<p>Adds an <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.html"><code>ALPNServerConnectionFactory</code></a> to the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html"><code>ServerConnector</code></a> configured by <code>jetty-ssl.xml</code> which allows the one SSL connector to support multiple protocols with the ALPN extension used to select the protocol to be used for each connection.</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="_constructing-a-serverconnector"><a class="anchor" href="#_constructing-a-serverconnector"></a><a class="link" href="#_constructing-a-serverconnector">Constructing a ServerConnector</a></h4>
<div class="paragraph">
<p>The services a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html"><code>ServerConnector</code></a> instance uses are set by constructor injection and once instantiated cannot be changed.
Many of the services may be defaulted with null or 0 values so that a reasonable default is used, thus for most purposes only the Server and the connection factories need to be passed to the connector constructor. In Jetty XML (that is, in <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-http.xml"><code>jetty-http.xml</code></a>) you can do this by:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.ServerConnector</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">factories</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.ConnectionFactory</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="comment">&lt;!-- insert one or more factories here --&gt;</span>
<span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="comment">&lt;!-- set connector fields here --&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>You can see the other arguments that can be passed when constructing a <code>ServerConnector</code> in the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html#ServerConnector%28org.eclipse.jetty.server.Server,%20java.util.concurrent.Executor,%20org.eclipse.jetty.util.thread.Scheduler,%20org.eclipse.jetty.io.ByteBufferPool,%20int,%20int,%20org.eclipse.jetty.server.ConnectionFactory&#8230;&#8203;%29">Javadoc</a>.
Typically the defaults are sufficient for almost all deployments.</p>
</div>
</div>
<div class="sect3">
<h4 id="jetty-connectors-network-settings"><a class="anchor" href="#jetty-connectors-network-settings"></a><a class="link" href="#jetty-connectors-network-settings">Network Settings</a></h4>
<div class="paragraph">
<p>You can configure connector network settings by calling setters on the connector before it is started.
For example, you can set the port with the Jetty XML:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.ServerConnector</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">factories</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="comment">&lt;!-- insert one or more factories here --&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">port</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>8080<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Values in Jetty XML can also be parameterized so that they may be passed from property files or set on the command line.
Thus typically the port is set within Jetty XML, but uses the <code>Property</code> element to be customizable:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.ServerConnector</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">factories</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="comment">&lt;!-- insert one or more factories here --&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">port</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.http.port</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">8080</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The network settings available for configuration on the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html"><code>ServerConnector</code></a> include:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 3. Connector Configuration</caption>
<colgroup>
<col style="width: 22%;">
<col style="width: 78%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Field</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">host</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The network interface this connector binds to as an IP address or a hostname.
If null or 0.0.0.0, bind to all interfaces.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">port</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The configured port for the connector or 0 a random available port may be used (selected port available via <code>getLocalPort()</code>).</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">idleTimeout</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The time in milliseconds that the connection can be idle before it is closed.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">defaultProtocol</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The name of the default protocol used to select a <code>ConnectionFactory</code> instance. This defaults to the first <code>ConnectionFactory</code> added to the connector.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">stopTimeout</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The time in milliseconds to wait before gently stopping a connector.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">acceptQueueSize</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The size of the pending connection backlog.
The exact interpretation is JVM and operating system specific and you can ignore it.
Higher values allow more connections to wait pending an acceptor thread.
Because the exact interpretation is deployment dependent, it is best to keep this value as the default unless there is a specific connection issue for a specific OS that you need to address.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">reuseAddress</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Allow the server socket to be rebound even if in <a href="http://www.ssfnet.org/Exchange/tcp/tcpTutorialNotes.html">TIME_WAIT</a>.
For servers it is typically OK to leave this as the default true.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect3">
<h4 id="jetty-connectors-http-configuration"><a class="anchor" href="#jetty-connectors-http-configuration"></a><a class="link" href="#jetty-connectors-http-configuration">HTTP Configuration</a></h4>
<div class="paragraph">
<p>The <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/HttpConfiguration.html"><code>HttpConfiguration</code></a> class holds the configuration for <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/HttpChannel.html"><code>HttpChannel</code></a>s, which you can create 1:1 with each HTTP connection or 1:n on a multiplexed HTTP/2 connection.
Thus a <code>HttpConfiguration</code> object is injected into both the HTTP and HTTP/2 connection factories.
To avoid duplicate configuration, the standard Jetty distribution creates the common <code>HttpConfiguration</code> instance in <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty.xml"><code>jetty.xml</code></a>, which is a <code>Ref</code> element then used in <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-http.xml"><code>jetty-http.xml</code></a>, <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-https.xml"><code>jetty-https.xml</code></a> and in <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-http2/http2-server/src/main/config/etc/jetty-http2.xml"><code>jetty-http2.xml</code></a>.</p>
</div>
<div class="paragraph">
<p>A typical configuration of <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/HttpConfiguration.html">HttpConfiguration</a> is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">httpConfig</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.HttpConfiguration</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">secureScheme</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>https<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">securePort</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.ssl.port</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">8443</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">outputBufferSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>32768<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">requestHeaderSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>8192<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">responseHeaderSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>8192<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This example HttpConfiguration may be used by reference to the ID &#8220;httpConfig&#8221;:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addConnector</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.ServerConnector</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">factories</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.ConnectionFactory</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Item&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.HttpConnectionFactory</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">config</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">httpConfig</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="comment">&lt;!-- ... --&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This same <code>httpConfig</code> is referenced by the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/SecuredRedirectHandler.html"><code>SecuredRedirectHandler</code></a> when redirecting secure requests.
Please note that if your <code>httpConfig</code> does not include a <code>secureScheme</code> or <code>securePort</code> or there is no <code>HttpConfiguration</code> present these types of secured requests will be returned a <code>403</code> error.</p>
</div>
<div class="paragraph">
<p>For SSL-based connectors (in <code>jetty-https.xml</code> and <code>jetty-http2.xml</code>), the common &#8220;httpConfig&#8221; instance is used as the basis to create an SSL specific configuration with ID &#8220;sslHttpConfig&#8221;:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">sslHttpConfig</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.HttpConfiguration</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">httpConfig</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addCustomizer</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.SecureRequestCustomizer</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This adds a <code>SecureRequestCustomizer</code> which adds SSL Session IDs and certificate information as request attributes.</p>
</div>
</div>
<div class="sect3">
<h4 id="_ssl-context-configuration"><a class="anchor" href="#_ssl-context-configuration"></a><a class="link" href="#_ssl-context-configuration">SSL Context Configuration</a></h4>
<div class="paragraph">
<p>The SSL/TLS connectors for HTTPS and HTTP/2 require a certificate to establish a secure connection.
Jetty holds certificates in standard JVM keystores and are configured as keystore and truststores on a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/util/ssl/SslContextFactory.Server.html"><code>SslContextFactory.Server</code></a> instance that is injected into an <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/SslConnectionFactory.html"><code>SslConnectionFactory</code></a> instance.
An example using the keystore distributed with Jetty (containing a self signed test certificate) is in <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-https.xml"><code>jetty-https.xml</code></a>.
Read more about SSL keystores in <a href="#configuring-ssl">Configuring SSL</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="_proxy-load-balancer-connection-configuration"><a class="anchor" href="#_proxy-load-balancer-connection-configuration"></a><a class="link" href="#_proxy-load-balancer-connection-configuration">Proxy / Load Balancer Connection Configuration</a></h4>
<div class="paragraph">
<p>Often a Connector needs to be configured to accept connections from an intermediary such as a Reverse Proxy and/or Load Balancer deployed in front of the server.
In such environments, the TCP/IP connection terminating on the server does not originate from the client, but from the intermediary, so that the Remote IP and port number can be reported incorrectly in logs and in some circumstances the incorrect server address and port may be used.</p>
</div>
<div class="paragraph">
<p>Thus Intermediaries typically implement one of several de facto standards to communicate to the server information about the original client connection terminating on the intermediary.
Jetty supports the <code>X-Forwarded-For</code> header and the <a href="http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt">Proxy Protocol</a> mechanisms as described below.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The XML files in the Jetty distribution contain commented out examples of both the <code>X-Forwarded-For</code> and <a href="http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt">Proxy Protocol</a> mechanisms.
When using those examples, it is recommended that the XML in the Jetty distribution is not edited.
Rather the files should be copied into a Jetty base directory and then modified.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect4">
<h5 id="_x-forward-for-configuration"><a class="anchor" href="#_x-forward-for-configuration"></a><a class="link" href="#_x-forward-for-configuration">X-Forward-for Configuration</a></h5>
<div class="paragraph">
<p>The <code>X-Forwarded-for</code> header and associated headers are a de facto standard where intermediaries add HTTP headers to each request they forward to describe the originating connection.
These headers can be interpreted by an instance of <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ForwardedRequestCustomizer.html"><code>ForwardedRequestCustomizer</code></a> which can be added to a <code>HttpConfiguration</code> as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">httpConfig</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.HttpConfiguration</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">outputBufferSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>32768<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">requestHeaderSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>8192<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">responseHeaderSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>8192<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addCustomizer</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.ForwardedRequestCustomizer</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_proxy-protocol"><a class="anchor" href="#_proxy-protocol"></a><a class="link" href="#_proxy-protocol">Proxy Protocol</a></h5>
<div class="paragraph">
<p>The <a href="http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt">Proxy Protocol</a> is the <em>de facto</em> standard created by HAProxy and used by environments such as Amazon Elastic Cloud.
This mechanism is independent of any protocol, so it can be used for HTTP2, TLS etc.
The information about the client connection is sent as a small data frame on each newly established connection.
In Jetty, this protocol can be handled by the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ProxyConnectionFactory.html"><code>ProxyConnectionFactory</code></a> which parses the data frame and then instantiates the next <code>ConnectionFactory</code> on the connection with an end point that has been customized with the data obtained about the original client connection.
The connection factory can be added to any <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html"><code>ServerConnector</code></a> and should be the first <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ConnectionFactory.html"><code>ConnectionFactory</code></a>.</p>
</div>
<div class="paragraph">
<p>An example of adding the factory to a HTTP connector is shown below:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addConnector</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.ServerConnector</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">factories</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.ConnectionFactory</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Item&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.ProxyConnectionFactory</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.HttpConnectionFactory</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">config</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">httpConfig</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">host</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.host</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">port</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.http.port</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">80</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span></code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="configuring-contexts"><a class="anchor" href="#configuring-contexts"></a><a class="link" href="#configuring-contexts">Configuring Contexts</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>This chapter discusses various options for configuring Jetty contexts.</p>
</div>
<div class="sect2">
<h3 id="setting-context-path"><a class="anchor" href="#setting-context-path"></a><a class="link" href="#setting-context-path">Setting a Context Path</a></h3>
<div class="paragraph">
<p>The context path is the prefix of a URL path that is used to select the context(s) to which an incoming request is passed. Typically a URL in a Java servlet server is of the format <code><a href="http://hostname.com/contextPath/servletPath/pathInfo" class="bare">http://hostname.com/contextPath/servletPath/pathInfo</a></code>, where each of the path elements can be zero or more / separated elements.
If there is no context path, the context is referred to as the <em>root</em> context.
The root context must be configured as <code>/</code> but is reported as the empty string by the servlet API <code>getContextPath()</code> method.</p>
</div>
<div class="paragraph">
<p>How you set the context path depends on how you deploy the web application (or <code>ContextHandler</code>).</p>
</div>
<div class="sect3">
<h4 id="using-embedded-deployment"><a class="anchor" href="#using-embedded-deployment"></a><a class="link" href="#using-embedded-deployment">Using Embedded Deployment</a></h4>
<div class="paragraph">
<p>If you run Jetty from code as an embedded server (see <a href="#advanced-embedding">Embedding</a>), setting the context path is a matter of calling the <code>setContextPath</code> method on the <code>ContextHandler</code> instance (or <code>WebAppContext</code> instance).</p>
</div>
</div>
<div class="sect3">
<h4 id="usng-the-context-provider"><a class="anchor" href="#usng-the-context-provider"></a><a class="link" href="#usng-the-context-provider">By naming convention</a></h4>
<div class="paragraph">
<p>If a web application is deployed using the WebAppProvider of the DeploymentManager without an XML IoC file, then the name of the WAR file is used to set the context path:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>If the WAR file is named myapp.war, then the context will be deployed with a context path of <code>/myapp</code></p>
</li>
<li>
<p>If the WAR file is named ROOT.WAR (or any case insensitive variation), then the context will be deployed with a context path of <code>/</code></p>
</li>
<li>
<p>If the WAR file is named ROOT-foobar.war ( or any case insensitive variation), then the context will be deployed with a context path of <code>/</code> and a virtual host of "foobar"</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="using-the-webapp-provider"><a class="anchor" href="#using-the-webapp-provider"></a><a class="link" href="#using-the-webapp-provider">By Deployer configuration</a></h4>
<div class="paragraph">
<p>If a web application is deployed using the <code>WebAppProvider</code> of the <code>DeploymentManager</code> with an XML IoC file to configure the context, then the <code>setContextPath</code> method can be called within that file.
For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/test<span class="tag">&lt;/Set&gt;</span>
...
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="embedding-web-inf-jetty-web.xml-file"><a class="anchor" href="#embedding-web-inf-jetty-web.xml-file"></a><a class="link" href="#embedding-web-inf-jetty-web.xml-file">Embedding a WEB-INF/jetty-web.xml File</a></h4>
<div class="paragraph">
<p>You can also set the context path for webapps by embedding a <code>WEB-INF/jetty-web.xml</code> file in the WAR, which uses the same XML IoC format as the deployer example above.
However this is not the preferred method as it requires the web application to be modified.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="ref-temporary-directories"><a class="anchor" href="#ref-temporary-directories"></a><a class="link" href="#ref-temporary-directories">Temporary Directories</a></h3>
<div class="paragraph">
<p>Jetty itself has no temporary directories, but you can assign a directory for each web application, into which the WAR is unpacked, JSPs compiled on-the-fly, etc.
If you do not assign a specific temporary directory, Jetty will create one as needed when your web application starts.
Whether you set the location of the temporary directory - or you let Jetty create one for you - you also have a choice to either keep or delete the temporary directory when the web application stops.</p>
</div>
<div class="sect3">
<h4 id="_the-default-temp-directory"><a class="anchor" href="#_the-default-temp-directory"></a><a class="link" href="#_the-default-temp-directory">The Default Temp Directory</a></h4>
<div class="paragraph">
<p>By default, Jetty will create a temporary directory for each web application. The name of the directory will be of the form:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>"jetty-"+host+"-"+port+"-"+resourceBase+"-_"+context+"-"+virtualhost+"-"+randomdigits+".dir"</pre>
</div>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>jetty-0.0.0.0-8080-test.war-_test-any-8900275691885214790.dir</pre>
</div>
</div>
<div class="paragraph">
<p>Where <code>0.0.0.0</code> is the host address, <code>8080</code> is the port, <code>test.war</code> is the resourceBase, <code>test</code> is the context path (with / converted to _), <code>any</code> is the virtual host, and <code>randomdigits</code> are a string of digits guaranteed to be unique.</p>
</div>
<div class="paragraph">
<p>Once the temp directory is created, it is retrievable as the value (as a File) of the context attribute <code>javax.servlet.context.tempdir.</code></p>
</div>
<div class="sect4">
<h5 id="_the-location-of-the-temp-directory"><a class="anchor" href="#_the-location-of-the-temp-directory"></a><a class="link" href="#_the-location-of-the-temp-directory">The location of the temp directory</a></h5>
<div class="paragraph">
<p>By default, Jetty will create this directory inside the directory named by the <code>java.io.tmpdir</code> System property.
You can instruct Jetty to use a different parent directory by setting the context attribute <code>org.eclipse.jetty.webapp.basetempdir</code> to the name of the desired parent directory.
The directory named by this attribute <em>must</em> exist and be <em>writeable</em>.</p>
</div>
<div class="paragraph">
<p>As usual with Jetty, you can either set this attribute in a context xml file, or you can do it in code.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of setting it in an xml file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/test<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>foo.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setAttribute</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>org.eclipse.jetty.webapp.basetempdir<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>/home/my/foo<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The equivalent in code is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">WebAppContext context = <span class="keyword">new</span> WebAppContext();
context.setContextPath(<span class="string"><span class="delimiter">&quot;</span><span class="content">/test</span><span class="delimiter">&quot;</span></span>);
context.setWar(<span class="string"><span class="delimiter">&quot;</span><span class="content">foo.war</span><span class="delimiter">&quot;</span></span>);
context.setAttribute(<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.basetempdir</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">/tmp/foo</span><span class="delimiter">&quot;</span></span>);</code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_setting-a-specific-temp-directory"><a class="anchor" href="#_setting-a-specific-temp-directory"></a><a class="link" href="#_setting-a-specific-temp-directory">Setting a Specific Temp Directory</a></h4>
<div class="paragraph">
<p>There are several ways to use a particular directory as the temporary directory:</p>
</div>
<div class="sect4">
<h5 id="_call-webappcontext-settempdirectorystring-dir"><a class="anchor" href="#_call-webappcontext-settempdirectorystring-dir"></a><a class="link" href="#_call-webappcontext-settempdirectorystring-dir">Call WebAppContext.setTempDirectory(String dir)</a></h5>
<div class="paragraph">
<p>As before this can be accomplished with an XML file or directly in code.
Here is an example of setting the temp directory in XML:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/test<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>foo.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tempDirectory</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/some/dir/foo<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>And here is an example of doing it with java code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">WebAppContext context = <span class="keyword">new</span> WebAppContext();
context.setContextPath(<span class="string"><span class="delimiter">&quot;</span><span class="content">/test</span><span class="delimiter">&quot;</span></span>);
context.setWar(<span class="string"><span class="delimiter">&quot;</span><span class="content">foo.war</span><span class="delimiter">&quot;</span></span>);
context.setTempDirectory(<span class="keyword">new</span> <span class="predefined-type">File</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">/some/dir/foo</span><span class="delimiter">&quot;</span></span>));</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_setting-the-javax-servlet-context-tempdir-context-attribute"><a class="anchor" href="#_setting-the-javax-servlet-context-tempdir-context-attribute"></a><a class="link" href="#_setting-the-javax-servlet-context-tempdir-context-attribute">Setting the javax.servlet.context.tempdir Context Attribute</a></h5>
<div class="paragraph">
<p>You should set this context attribute with the name of directory you want to use as the temp directory.
Again, you can do this in XML:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/test<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>foo.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setAttribute</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>javax.servlet.context.tempdir<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>/some/dir/foo<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Or in java:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">WebAppContext context = <span class="keyword">new</span> WebAppContext();
context.setContextPath(<span class="string"><span class="delimiter">&quot;</span><span class="content">/test</span><span class="delimiter">&quot;</span></span>);
context.setWar(<span class="string"><span class="delimiter">&quot;</span><span class="content">foo.war</span><span class="delimiter">&quot;</span></span>);
context.setAttribute(<span class="string"><span class="delimiter">&quot;</span><span class="content">javax.servlet.context.tempdir</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">/some/dir/foo</span><span class="delimiter">&quot;</span></span>);</code></pre>
</div>
</div>
<div class="paragraph">
<p>Once a temporary directory has been created by either of these methods, a file instance for it is set as the value of the <code>javax.servlet.context.tempdir</code> attribute of the web application.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Be wary of setting an explicit temp directory if you are likely to change the jars in WEB-INF/lib between redeployments.
There is a JVM bug concerning <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4774421">caching of jar contents.</a>
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect4">
<h5 id="_setting-the-temp-directory-on-the-command-line"><a class="anchor" href="#_setting-the-temp-directory-on-the-command-line"></a><a class="link" href="#_setting-the-temp-directory-on-the-command-line">Setting the Temp Directory on the Command Line</a></h5>
<div class="paragraph">
<p>You can set the location of the temp directory on the command line when Jetty starts up in two ways.
First is the most straightforward, simply add it to your command line when starting Jetty.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar -Djava.io.tmpdir=/path/to/desired/directory</code></pre>
</div>
</div>
<div class="paragraph">
<p>Alternately, this can be defined in a <a href="#startup-modules">module.</a>
The <code>jvm</code> module packaged with Jetty is set up to add additional JVM options.
After enabling the module (using the <code>--add-to-start=jvm</code> command), edit the <code>jvm.ini</code> file and add the location to the temporary directory.
You will also need verify the line including the <code>--exec</code> command is not commented out, as this is required for Jetty to start a new, forked JVM.
Below is an example of the standard <code>jvm.ini</code> file altered to include a reference to a temp directory.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># ---------------------------------------
# Module: jvm
# A noop module that creates an ini template useful for
# setting JVM arguments (eg -Xmx )
# ---------------------------------------
--module=jvm
## JVM Configuration
## If JVM args are include in an ini file then --exec is needed
## to start a new JVM from start.jar with the extra args.
##
## If you wish to avoid an extra JVM running, place JVM args
## on the normal command line and do not use --exec
--exec
# -Xmx2000m
# -Xmn512m
# -XX:+UseConcMarkSweepGC
# -XX:ParallelCMSThreads=2
# -XX:+CMSClassUnloadingEnabled
# -XX:+UseCMSCompactAtFullCollection
# -XX:CMSInitiatingOccupancyFraction=80
# -internal:gc
# -XX:+PrintGCDateStamps
# -XX:+PrintGCTimeStamps
# -XX:+PrintGCDetails
# -XX:+PrintTenuringDistribution
# -XX:+PrintCommandLineFlags
# -XX:+DisableExplicitGC
-Djava.io.tmpdir=/path/to/desired/directory</code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_the-work-directory"><a class="anchor" href="#_the-work-directory"></a><a class="link" href="#_the-work-directory">The "work" Directory</a></h4>
<div class="paragraph">
<p>It is possible to create a directory named <code>work</code> in the <code>$\{jetty.base}</code> directory.
If such a directory is found, it is assumed you want to use it as the parent directory for all of the temporary directories of the webapps in <code>$\{jetty.base}</code>.
Moreover, as has historically been the case, these temp directories inside the work directory are not cleaned up when Jetty exits (or more correctly speaking, the <code>temp</code> directory corresponding to a context is not cleaned up when that context stops).</p>
</div>
<div class="paragraph">
<p>When a <code>work</code> directory is used, the algorithm for generating the name of the context-specific temp directories omits the random digit string.
This ensures the name of the directory remains consistent across context restarts.</p>
</div>
</div>
<div class="sect3">
<h4 id="_persisting-the-temp-directory"><a class="anchor" href="#_persisting-the-temp-directory"></a><a class="link" href="#_persisting-the-temp-directory">Persisting the temp directory</a></h4>
<div class="paragraph">
<p>Sometimes it is useful to keep the contents of the temporary directory between restarts of the web application.
By default, Jetty will <strong>not</strong> persist the temp directory.
To configure Jetty to keep it, use <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html">WebAppContext.setPersistTempDirectory(true)</a>.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Be aware that if you call <code>setPersistTempDirectory(true)</code>, but let Jetty create a new temp directory each time (i.e. you do NOT set an explicit temp directory), then you will accumulate temp directories in your chosen temp directory location.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
</div>
<div class="sect2">
<h3 id="custom-error-pages"><a class="anchor" href="#custom-error-pages"></a><a class="link" href="#custom-error-pages">Creating Custom Error Pages</a></h3>
<div class="paragraph">
<p>The following sections describe several ways to create custom error pages in Jetty.</p>
</div>
<div class="sect3">
<h4 id="_defining-error-pages-in-web-xml"><a class="anchor" href="#_defining-error-pages-in-web-xml"></a><a class="link" href="#_defining-error-pages-in-web-xml">Defining error pages in web.xml</a></h4>
<div class="paragraph">
<p>You can use the standard webapp configuration file located in <code>webapp/WEB-INF/web.xml</code> to map errors to specific URLs with the <code>error-page</code> element.
This element creates a mapping between the error-code or exception-type to the location of a resource in the web application.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>error-code</code> - an integer value</p>
</li>
<li>
<p><code>exception-type</code> - a fully qualified class name of a Java Exception type</p>
</li>
<li>
<p><code>location</code> - location of the resource in the webapp relative to the root of the web application. Value should start with <code>/</code>.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Error code example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;error-page&gt;</span>
<span class="tag">&lt;error-code&gt;</span>404<span class="tag">&lt;/error-code&gt;</span>
<span class="tag">&lt;location&gt;</span>/jspsnoop/ERROR/404<span class="tag">&lt;/location&gt;</span>
<span class="tag">&lt;/error-page&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Exception example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;error-page&gt;</span>
<span class="tag">&lt;exception-type&gt;</span>java.io.IOException<span class="tag">&lt;/exception-type&gt;</span>
<span class="tag">&lt;location&gt;</span>/jspsnoop/IOException<span class="tag">&lt;/location&gt;</span>
<span class="tag">&lt;/error-page&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The error page mappings created with the error-page element will redirect to a normal URL within the web application and will be handled as a normal request to that location and thus may be static content, a JSP or a filter and/or servlet.
When handling a request generated by an error redirection, the following request attributes are set and are available to generate dynamic content:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">javax.servlet.error.exception</dt>
<dd>
<p>The exception instance that caused the error (or null).</p>
</dd>
<dt class="hdlist1">javax.servlet.error.exception_type</dt>
<dd>
<p>The class name of the exception instance that caused the error (or null).</p>
</dd>
<dt class="hdlist1">javax.servlet.error.message</dt>
<dd>
<p>The error message.</p>
</dd>
<dt class="hdlist1">javax.servlet.error.request_uri</dt>
<dd>
<p>The URI of the request with an error.</p>
</dd>
<dt class="hdlist1">javax.servlet.error.servlet_name</dt>
<dd>
<p>The Servlet name of the servlet that the request was
dispatched to.</p>
</dd>
<dt class="hdlist1">javax.servlet.error.status_code</dt>
<dd>
<p>The status code of the error (e.g. 404, 500 etc.).</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="_configuring-error-pages-context-files"><a class="anchor" href="#_configuring-error-pages-context-files"></a><a class="link" href="#_configuring-error-pages-context-files">Configuring error pages context files</a></h4>
<div class="paragraph">
<p>You can use context IoC XML files to configure the default error page mappings with more flexibility than is available with <code>web.xml</code>, specifically with the support of error code ranges.
Context files are normally located in <code>${jetty.base}/webapps/</code> (see <code>DeployerManager</code> for more details) and an example of more flexible error page mapping is below:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/test<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.base</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/webapps/test
<span class="tag">&lt;/Set&gt;</span>
<span class="comment">&lt;!-- by Code --&gt;</span>
<span class="tag">&lt;Get</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">errorHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addErrorPage</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">int</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>404<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/jspsnoop/ERROR/404<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Get&gt;</span>
<span class="comment">&lt;!-- by Exception --&gt;</span>
<span class="tag">&lt;Get</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">errorHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addErrorPage</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.lang.Class</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">forName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>java.io.IOException<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/jspsnoop/IOException<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Get&gt;</span>
<span class="comment">&lt;!-- by Code Range --&gt;</span>
<span class="tag">&lt;Get</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">errorHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addErrorPage</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">int</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>500<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">int</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>599<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/dump/errorCodeRangeMapping<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Get&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_custom-errorhandler-class"><a class="anchor" href="#_custom-errorhandler-class"></a><a class="link" href="#_custom-errorhandler-class">Custom ErrorHandler class</a></h4>
<div class="paragraph">
<p>If no error page mapping is defined, or if the error page resource itself has an error, then the error page will be generated by an instance of <code>ErrorHandler</code> configured either the Context or the Server.
An <code>ErrorHandler</code> may extend the <code>ErrorHandler</code> class and may totally replace the handle method to generate an error page, or it can implement some or all of the following methods to partially modify the error pages:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="type">void</span> handle(<span class="predefined-type">String</span> target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) <span class="directive">throws</span> <span class="exception">IOException</span>
<span class="type">void</span> handleErrorPage(HttpServletRequest request, <span class="predefined-type">Writer</span> writer, <span class="type">int</span> code, <span class="predefined-type">String</span> message) <span class="directive">throws</span> <span class="exception">IOException</span>
<span class="type">void</span> writeErrorPage(HttpServletRequest request, <span class="predefined-type">Writer</span> writer, <span class="type">int</span> code, <span class="predefined-type">String</span> message, <span class="type">boolean</span> showStacks) <span class="directive">throws</span> <span class="exception">IOException</span>
<span class="type">void</span> writeErrorPageHead(HttpServletRequest request, <span class="predefined-type">Writer</span> writer, <span class="type">int</span> code, <span class="predefined-type">String</span> message) <span class="directive">throws</span> <span class="exception">IOException</span>
<span class="type">void</span> writeErrorPageBody(HttpServletRequest request, <span class="predefined-type">Writer</span> writer, <span class="type">int</span> code, <span class="predefined-type">String</span> message, <span class="type">boolean</span> showStacks) <span class="directive">throws</span> <span class="exception">IOException</span>
<span class="type">void</span> writeErrorPageMessage(HttpServletRequest request, <span class="predefined-type">Writer</span> writer, <span class="type">int</span> code, <span class="predefined-type">String</span> message, <span class="predefined-type">String</span> uri) <span class="directive">throws</span> <span class="exception">IOException</span>
<span class="type">void</span> writeErrorPageStacks(HttpServletRequest request, <span class="predefined-type">Writer</span> writer) <span class="directive">throws</span> <span class="exception">IOException</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>An <code>ErrorHandler</code> instance may be set on a Context by calling the <code>ContextHandler.setErrorHandler</code> method. This can be done by embedded code or via context IoC XML.
For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.handler.ContextHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">errorHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.acme.handler.MyErrorHandler</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
...
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>An <code>ErrorHandler</code> instance may be set on the entire server by setting it as a dependent bean on the Server instance.
This can be done by calling <code>Server.addBean(Object)</code> via embedded code or in <code>jetty.xml</code> IoC XML:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addBean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.acme.handler.MyErrorHandler</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
...
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_server-level-404-error"><a class="anchor" href="#_server-level-404-error"></a><a class="link" href="#_server-level-404-error">Server level 404 error</a></h4>
<div class="paragraph">
<p>It is possible to get a 'page not found' when a request is made to the server for a resource that is outside of any registered contexts.
As an example, you have a domain name pointing to your public server IP, yet no context is registered with Jetty to serve pages for that domain.
As a consequence, the server, by default, gives a listing of all contexts running on the server.</p>
</div>
<div class="paragraph">
<p>One of the quickest ways to avoid this behavior is to create a catch all context.
Create a "root" web app mapped to the "/" URI, and use the <code>index.html</code> redirect to whatever place with a header directive.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="setting-form-size"><a class="anchor" href="#setting-form-size"></a><a class="link" href="#setting-form-size">Setting Max Form Size</a></h3>
<div class="paragraph">
<p>When a client issues a POST request with <code>Content-Type: application/x-www-form-urlencoded</code> there are 2 configurable limits imposed to help protect the server against denial of service attacks by malicious clients sending huge amounts of data.</p>
</div>
<div class="paragraph">
<p>There is a maximum form size limit, and a maximum form keys limit.</p>
</div>
<div class="paragraph">
<p>The default maximum form size Jetty permits is 200000 bytes.
The default maximum form keys Jetty permits is 1000 keys.</p>
</div>
<div class="paragraph">
<p>You can change these defaults for a particular webapp, or all webapps within the same JVM.</p>
</div>
<div class="sect3">
<h4 id="_for-a-single-webapp"><a class="anchor" href="#_for-a-single-webapp"></a><a class="link" href="#_for-a-single-webapp">For a Single Webapp</a></h4>
<div class="paragraph">
<p>The methods to invoke are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>ContextHandler.setMaxFormContentSize(int maxSize);</code></p>
</li>
<li>
<p><code>ContextHandler.setMaxFormKeys(int max);</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>This can be done either in a context XML deployment descriptor external to the webapp, or in a <code>jetty-web.xml</code> file in the webapp&#8217;s <code>WEB-INF</code> directory.</p>
</div>
<div class="paragraph">
<p>In either case the syntax of the XML file is the same:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="comment">&lt;!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --&gt;</span>
<span class="comment">&lt;!-- Max Form Size --&gt;</span>
<span class="comment">&lt;!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">maxFormContentSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>400000<span class="tag">&lt;/Set&gt;</span>
<span class="comment">&lt;!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --&gt;</span>
<span class="comment">&lt;!-- Max Form Keys --&gt;</span>
<span class="comment">&lt;!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">maxFormKeys</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>400<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_for-all-apps-in-the-jvm"><a class="anchor" href="#_for-all-apps-in-the-jvm"></a><a class="link" href="#_for-all-apps-in-the-jvm">For All Apps in the JVM</a></h4>
<div class="paragraph">
<p>Use the system properties:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>org.eclipse.jetty.server.Request.maxFormContentSize</code> - the maximum size of Form Content allowed</p>
</li>
<li>
<p><code>org.eclipse.jetty.server.Request.maxFormKeys</code> - the maximum number of Form Keys allowed</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>This can be set on the command line or in the <code>$JETTY_BASE\start.ini</code> or any <code>$JETTY_BASE\start.d\*.ini</code> <a href="#startup-modules">module ini file.</a>
Using <code>$JETTY_BASE\start.d\server.ini</code> as an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="console"># ---------------------------------------
# Module: server
# Enables the core Jetty server on the classpath.
# ---------------------------------------
--module=server
### Common HTTP configuration
## Scheme to use to build URIs for secure redirects
# jetty.httpConfig.secureScheme=https
...
-Dorg.eclipse.jetty.server.Request.maxFormContentSize=400000
-Dorg.eclipse.jetty.server.Request.maxFormKeys=400</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="advanced-debugging"><a class="anchor" href="#advanced-debugging"></a><a class="link" href="#advanced-debugging">Debugging</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_options"><a class="anchor" href="#_options"></a><a class="link" href="#_options">Options</a></h3>
<div class="paragraph">
<p>Given how flexible Jetty is in how it can be configured and deployed into development and production, there exists a wealth of different options for debugging your application in you favorite environment.
In this section we will gather up some of these different options available and explain how you can use them.
If you would like to contribute to this section simply fork the repository and contribute the information, or open a github issue with the information and we&#8217;ll bring it over.</p>
</div>
</div>
<div class="sect2">
<h3 id="enable-remote-debugging"><a class="anchor" href="#enable-remote-debugging"></a><a class="link" href="#enable-remote-debugging">Enable remote debugging</a></h3>
<div class="sect3">
<h4 id="remote-debugging"><a class="anchor" href="#remote-debugging"></a><a class="link" href="#remote-debugging">Remote Debugging</a></h4>
<div class="paragraph">
<p>If you have a web application deployed into Jetty you can interact with it remotely from a debugging perspective easily.
The basics are that you must start up the remote JVM with additional parameters and then start up a remote debugging session in Eclipse for the webapp in question.
This is easily accomplished.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
This example assumes you are deploying your web application into a jetty-base.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect4">
<h5 id="_starting-jetty"><a class="anchor" href="#_starting-jetty"></a><a class="link" href="#_starting-jetty">Starting Jetty</a></h5>
<div class="paragraph">
<p>Assuming you have your webapp deployed into jetty, there are two different ways to approach this:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Via command line</dt>
<dd>
<p>Add the required parameters on the commandline like so.</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ java -Xdebug -agentlib:jdwp=transport=dt_socket,address=9999,server=y,suspend=n -jar start.jar</code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">Via <code>start.ini</code></dt>
<dd>
<p>This approach is best used if you want to debug a particular jetty-base and not have to remember the commandline incantations.</p>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Edit the <code>start.ini</code> and uncomment the --exec line, this is required if you are adding jvm options to the start.ini file as jetty-start must generate the classpath required and fork a new jvm.</p>
</li>
<li>
<p>Add the parameters mentioned above in the Command Line option so your start.ini looks like this:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">#===========================================================
# Configure JVM arguments.
# If JVM args are include in an ini file then --exec is needed
# to start a new JVM from start.jar with the extra args.
# If you wish to avoid an extra JVM running, place JVM args
# on the normal command line and do not use --exec
#-----------------------------------------------------------
--exec
-Xdebug
-agentlib:jdwp=transport=dt_socket,address=9999,server=y,suspend=n
# -Xmx2000m
# -Xmn512m
# -XX:+UseConcMarkSweepGC
# -XX:ParallelCMSThreads=2
# -XX:+CMSClassUnloadingEnabled
# -XX:+UseCMSCompactAtFullCollection
# -XX:CMSInitiatingOccupancyFraction=80
# -verbose:gc
# -XX:+PrintGCDateStamps
# -XX:+PrintGCTimeStamps
# -XX:+PrintGCDetails
# -XX:+PrintTenuringDistribution
# -XX:+PrintCommandLineFlags
# -XX:+DisableExplicitGC</code></pre>
</div>
</div>
<div class="paragraph">
<p>Uncomment any other jvm environmental options you so desire for your debugging session.</p>
</div>
</li>
<li>
<p>Regardless of the option chosen, you should see the following lines at the top of your jetty startup.</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Listening for transport dt_socket at address: 9999</code></pre>
</div>
</div>
</li>
</ol>
</div>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_linking-with-your-ide"><a class="anchor" href="#_linking-with-your-ide"></a><a class="link" href="#_linking-with-your-ide">Linking with your IDE</a></h5>
<div class="paragraph">
<p>Refer to the documentation for your ide:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#debugging-with-intellij">Debugging With IntelliJ</a></p>
</li>
<li>
<p><a href="#debugging-with-eclipse">Debugging With Eclipse</a></p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="debugging-with-intellij"><a class="anchor" href="#debugging-with-intellij"></a><a class="link" href="#debugging-with-intellij">Debugging With IntelliJ</a></h3>
<div class="paragraph">
<p>There are a number of options available to debug your application in IntelliJ.</p>
</div>
<div class="paragraph">
<p>If not done already prepare your application for remote debugging as described here: <a href="#enable-remote-debugging">Enable remote debugging</a></p>
</div>
<div class="sect3">
<h4 id="_linking-with-intellij"><a class="anchor" href="#_linking-with-intellij"></a><a class="link" href="#_linking-with-intellij">Linking with IntelliJ</a></h4>
<div class="paragraph">
<p>Next we need to link the IntelliJ project with the deployed webapp.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Within IntelliJ, open the project containing the webapp deployed into jetty that you want to debug. Select<strong>Run &#8594; Edit Configurations</strong>.
Add a new configuration by clicking the "+" icon. Choose <strong>Remote</strong>.
Make sure the port you choose is the same as the one you added in <a href="#enable-remote-debugging">Enable remote debugging</a>.</p>
<div class="paragraph">
<p><span class="image"><img src="intellij_new_remote_config.png" alt="image" width="800"></span></p>
</div>
</li>
<li>
<p>Next in your webapp you can set a breakpoint within a servlet which when it is tripped will halt the remote jvm&#8217;s processing thread to await for debugging commands from your IntelliJ instance.
To set a breakpoint, simply open the servlet or any other class you want to debug and click left to the line you want to set the breakpoint at (where the red dot is on the next screenshot).
The red dot and red background on the line mark the breakpoint.</p>
<div class="paragraph">
<p><span class="image"><img src="intellij_set_breakpoint.png" alt="image" width="800"></span></p>
</div>
</li>
<li>
<p>Accessing that servlet within your browser, pointed at your remote debug configured jetty-home, should transition your IntelliJ instance to the standard debugger view.</p>
<div class="paragraph">
<p><span class="image"><img src="intellij_debug_view.png" alt="image" width="800"></span></p>
</div>
</li>
</ol>
</div>
</div>
<div class="sect3">
<h4 id="intellij-within-intellij"><a class="anchor" href="#intellij-within-intellij"></a><a class="link" href="#intellij-within-intellij">Within IntelliJ</a></h4>
<div class="paragraph">
<p>Since Jetty can be incredibly simple to embed, many people choose to create a small <code>main</code> method which they can launch directly within IntelliJ in order to more easily debug their entire application.
The best place to get started on this approach is to look through <a href="#embedding-jetty">Embedding Jetty</a> and the <a href="#embedded-examples">Embedded Examples</a> sections.</p>
</div>
<div class="paragraph">
<p>Once you have a main method defined in order to launch your application, open the source file and right-click the main method.
Select <strong>Debug</strong> or simply hit CTRL+SHIFT+D.
In your <strong>Console</strong> tab within IntelliJ you should see your application startup and once it has completed startup you should be able to configure breakpoints and hit the Jetty instance as normal via your web browser.
The same thing works for unit tests.
Instead of the main method run debug on the test method you want to debug.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="intellij_select_debug.png" alt="image" width="800"></span></p>
</div>
<div class="paragraph">
<p>Debugging in IntelliJ is extremely powerful.
For example it&#8217;s possible to have conditional breakpoints that only trigger a break if the configured conditions are met.
Have a look at the various tutorials in the internet or the <a href="http://www.jetbrains.com/idea/webhelp/getting-help.html">IntelliJ documentation</a> for further details.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
You can easily configure logging through a <code>jetty-logging.properties</code> file.
If this file is on your classpath then Jetty will use it for configuring logging, we use this approach extensively throughout Jetty development and it makes life ever so much easier.
You can see this in action in the <a href="#configuring-jetty-stderrlog">The jetty-logging.properties file</a> section.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
</div>
<div class="sect2">
<h3 id="debugging-with-eclipse"><a class="anchor" href="#debugging-with-eclipse"></a><a class="link" href="#debugging-with-eclipse">Debugging With Eclipse</a></h3>
<div class="paragraph">
<p>There are a number of options available to debug your application in Eclipse.</p>
</div>
<div class="paragraph">
<p>If not done already prepare your application for remote debugging as described here: <a href="#enable-remote-debugging">Enable remote debugging</a></p>
</div>
<div class="sect3">
<h4 id="_linking-with-eclipse"><a class="anchor" href="#_linking-with-eclipse"></a><a class="link" href="#_linking-with-eclipse">Linking with Eclipse</a></h4>
<div class="paragraph">
<p>Next we need to link the Eclipse project with the deployed webapp.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Within Eclipse, right-click on the project containing the webapp deployed into jetty and select <strong>Debug &#8594; Debug Configurations</strong> and create a new configuration of <strong>Remote Java Application</strong>.
Make sure the port you choose is the same as the one you added in <a href="#enable-remote-debugging">Enable remote debugging</a>.</p>
<div class="paragraph">
<p><span class="image"><img src="debug-eclipse-1.png" alt="image" width="576"></span></p>
</div>
</li>
<li>
<p>Next in your webapp you can set a breakpoint within a servlet which when it is tripped will halt the remote jvm&#8217;s processing thread to await for debugging commands from your Eclipse instance.</p>
<div class="paragraph">
<p><span class="image"><img src="debug-eclipse-2.png" alt="image" width="576"></span></p>
</div>
</li>
<li>
<p>Accessing that servlet within your browser, pointed at your remote debug configurated jetty-home, should transition your Eclipse instance to the standard Debug view.</p>
<div class="paragraph">
<p><span class="image"><img src="debug-eclipse-3.png" alt="image" width="576"></span></p>
</div>
</li>
</ol>
</div>
</div>
<div class="sect3">
<h4 id="eclipse-within-eclipse"><a class="anchor" href="#eclipse-within-eclipse"></a><a class="link" href="#eclipse-within-eclipse">Within Eclipse</a></h4>
<div class="paragraph">
<p>Since Jetty can be incredibly simple to embed, many people choose to create a small <code>main</code> method which they can launch directly within Eclipse in order to more easily debug their entire application.
The best place to get started on this approach is to look through <a href="#embedding-jetty">Embedding Jetty</a> and the <a href="#embedded-examples">Embedded Examples</a> sections.</p>
</div>
<div class="paragraph">
<p>Once you have a main method defined in order to launch your application, right-click on the source file and select<strong>Debug As &#8594; Java Application</strong>.
In your <strong>Console</strong> tab within Eclipse you should see your application startup and once it has completed startup you should be able to configure breakpoints and hit the Jetty instance as normal via your web browser.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
You can easily configure logging through a <code>jetty-logging.properties</code>
file. If this file is on your classpath then Jetty will use it for
configuring logging, we use this approach extensively throughout Jetty
development and it makes life ever so much easier. You can see this in
action in the <a href="#configuring-jetty-stderrlog">The jetty-logging.properties file</a> section.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="configuring-deployment"><a class="anchor" href="#configuring-deployment"></a><a class="link" href="#configuring-deployment">Deploying to Jetty</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>This chapter discusses various ways to deploy applications with Jetty.
Topics range from deployment bindings to deploying third party products.
It also includes information about the Deployment Manager and WebApp Provider.</p>
</div>
<div class="sect2">
<h3 id="configuring-specific-webapp-deployment"><a class="anchor" href="#configuring-specific-webapp-deployment"></a><a class="link" href="#configuring-specific-webapp-deployment">Configuring a Specific Web Application Deployment</a></h3>
<div class="paragraph">
<p>Using the Automatic Web Application Deployment model is quick and easy, but sometimes you might need to tune certain deployment properties (for example, you want to deploy with a context path that is not based on the file name, or you want to define a special database connection pool just for this web application).
You can use a <a href="#deployable-descriptor-file">Jetty Deployable Descriptor XML File</a> to accomplish such tuning.</p>
</div>
<div class="sect3">
<h4 id="deployable-descriptor-file"><a class="anchor" href="#deployable-descriptor-file"></a><a class="link" href="#deployable-descriptor-file">Jetty Deployable Descriptor XML File</a></h4>
<div class="paragraph">
<p>Jetty supports deploying Web Applications via XML files which will build an instance of a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ContextHandler.html">ContextHandler</a> that Jetty can then deploy.</p>
</div>
</div>
<div class="sect3">
<h4 id="using-basic-descriptor-files"><a class="anchor" href="#using-basic-descriptor-files"></a><a class="link" href="#using-basic-descriptor-files">Using Basic Descriptor Files</a></h4>
<div class="paragraph">
<p>In a default Jetty installation, Jetty scans its <code>$JETTY_HOME/webapps</code> directory for context deployment descriptor files.
To deploy a web application using such a file, simply place the file in that directory.</p>
</div>
<div class="paragraph">
<p>The deployment descriptor file itself is an xml file that configures a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a> class.
For a basic installation only two properties need configured:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">war</dt>
<dd>
<p>The filesystem path to the web application file (or directory)</p>
</dd>
<dt class="hdlist1">contextPath</dt>
<dd>
<p>The context path to use for the web application</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>For example, here is a descriptor file that deploys the file <code>/opt/myapp/myapp.war</code> to the context path <code>/wiki</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/wiki<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/opt/myapp/myapp.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Both <code>SystemProperty</code> and <code>Property</code> elements can be used in the descriptor file.
For example, if the system property is set to <code>myapp.home=/opt/myapp</code>, the previous example can be rewritten as:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/wiki<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myapp.home</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/myapp.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>If the home path for an application needs altered, only the system property needs changed.
This is useful if the version of an app is frequently changed.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
To ensure your <code>web.xml</code> files are validated, you will need to set the <code>validateXml</code> attribute to true as described <a href="#jetty-xml-dtd">here.</a>
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="configuring-advanced-descriptor-files"><a class="anchor" href="#configuring-advanced-descriptor-files"></a><a class="link" href="#configuring-advanced-descriptor-files">Configuring Advanced Descriptor Files</a></h4>
<div class="paragraph">
<p>Official documentation for the for the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a> class lists all the properties that can be set.
Here are some examples that configure advanced options in the descriptor file.</p>
</div>
<div class="paragraph">
<p>This first example tells Jetty not to expand the WAR file when deploying it.
This can help make it clear that users should not make changes to the temporary unpacked WAR because such changes do not persist, and therefore do not apply the next time the web application deploys.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/wiki<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myapp.home</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/myapp.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">extractWAR</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>false<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The next example retrieves the JavaEE Servlet context and sets an initialization parameter on it.
The <code>setAttribute</code> method can also be used to set a Servlet context attribute.
However, since the <code>web.xml</code> for the web application is processed after the deployment descriptor, the <code>web.xml</code> values overwrite identically named attributes from the deployment descriptor.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/wiki<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myapp.home</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/myapp.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Get</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">ServletContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setInitParameter</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>myapp.config<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myapp.home</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/config/app-config.xml<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Get&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The following example sets a special <code>web.xml</code> override descriptor.
This descriptor is processed after the web application&#8217;s <code>web.xml</code>, so it may override identically named attributes.
This feature is useful when adding parameters or additional Servlet mappings without breaking open a packed WAR file.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/wiki<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myapp.home</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/myapp.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">overrideDescriptor</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/opt/myapp/overlay-web.xml<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The next example configures not only the web application context, but also a database connection pool (see <a href="#jndi-datasource-examples">Datasource Examples</a>) that the application can then use.
If the <code>web.xml</code> does not include a reference to this data source, an override descriptor mechanism (as shown in the previous example) can be used to include it.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/wiki<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myapp.home</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/myapp.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.apache.commons.dbcp.BasicDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">driverClassName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>org.some.Driver<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">url</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.url<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">username</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>There are many other settings that can be changed in a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a>.
The <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html">javadoc</a> for <code>WebAppContext</code> is a good source of information.
Also see the documentation on <a href="#troubleshooting-zip-exceptions">avoiding zip file exceptions</a> for a description of <code>WebAppContext</code> settings that determine such things as whether or not the war is automatically unpacked during deployment, or whether certain sections of a webapp are copied to a temporary location.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="configuring-webapps"><a class="anchor" href="#configuring-webapps"></a><a class="link" href="#configuring-webapps">Deployment Processing of WebAppContexts</a></h3>
<div class="paragraph">
<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>web.xml</code> and <code>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>
</div>
<div class="paragraph">
<p>If instead you&#8217;re looking for information on how to configure a specific <code>WebAppContext</code> - such as its context path, whether it should be unpacked or not - then you can find that in the section entitled <a href="#configuring-specific-webapp-deployment">Configuring a Specific WebApp Deployment</a>.</p>
</div>
<div class="sect3">
<h4 id="webapp-configurations"><a class="anchor" href="#webapp-configurations"></a><a class="link" href="#webapp-configurations">Configuration Classes</a></h4>
<div class="paragraph">
<p>As a webapp is being deployed, a series of <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/Configuration.html">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 href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html">org.eclipse.jetty.webapp.WebAppContex</a>t:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 4. Default Configuration classes</caption>
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebInfConfiguration.html">org.eclipse.jetty.webapp.WebInfConfiguration</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Extracts war, orders jars and defines classpath</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebXmlConfiguration.html">org.eclipse.jetty.webapp.WebXmlConfiguration</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Processes a WEB-INF/web.xml file</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/MetaInfConfiguration.html">org.eclipse.jetty.webapp.MetaInfConfiguration</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Looks in container and webapp jars for META-INF/resources and
META-INF/web-fragment.xml</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/FragmentConfiguration.html">org.eclipse.jetty.webapp.FragmentConfiguration</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Processes all discovered META-INF/web-fragment.xml files</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.html">org.eclipse.jetty.webapp.JettyWebXmlConfiguration</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Processes a WEB-INF/jetty-web.xml file</p></td>
</tr>
</tbody>
</table>
<div class="sect4">
<h5 id="_anatomy-of-a-configuration-class"><a class="anchor" href="#_anatomy-of-a-configuration-class"></a><a class="link" href="#_anatomy-of-a-configuration-class">Anatomy of a Configuration Class</a></h5>
<div class="paragraph">
<p>A Configuration class is called 5 times in different phases of the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext&#8217;s</code></a> lifecycle:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">preConfigure</dt>
<dd>
<p>As the <code>WebAppContext</code> is starting up this phase is executed.
The <code>Configuration</code> should discover any of the resources it will need during the subsequent phases.</p>
</dd>
<dt class="hdlist1">configure</dt>
<dd>
<p>This phase is where the work of the class is done, usually using the resources discovered during the <code>preConfigure</code> phase.</p>
</dd>
<dt class="hdlist1">postConfigure</dt>
<dd>
<p>This phase allows the <code>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>WebAppContext</code>.</p>
</dd>
<dt class="hdlist1">deconfigure</dt>
<dd>
<p>This phase occurs whenever a <code>WebAppContext</code> is being stopped and allows the Configuration to undo any resources/metadata that it created.
A <code>WebAppContext</code> should be able to be cleanly start/stopped multiple times without resources being held.</p>
</dd>
<dt class="hdlist1">destroy</dt>
<dd>
<p>This phase is called when a <code>WebAppContext</code> is actually removed from service.
For example, the war file associated with it is deleted from the $JETTY_HOME/webapps directory.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Each phase is called on each <code>Configuration</code> class in the order in which the <code>Configuration</code> class is listed.
Using the default <code>Configuration</code> classes as an example, <code>preConfigure()</code> will be called on <code>WebInfConfiguration</code>, <code>WebXmlConfiguration</code>, <code>MetaInfConfiguration</code>, <code>FragmentConfiguration</code> and then <code>JettyWebXmlConfiguration</code>.
The cycle begins again for the <code>configure()</code> phase and again for the <code>postConfigure()</code> phases.
The cycle is repeated <em>in reverse order</em> for the <code>deconfigure()</code> and eventually the <code>destroy()</code> phases.</p>
</div>
</div>
<div class="sect4">
<h5 id="_extending-container-support-by-creating-extra-configurations"><a class="anchor" href="#_extending-container-support-by-creating-extra-configurations"></a><a class="link" href="#_extending-container-support-by-creating-extra-configurations">Extending Container Support by Creating Extra Configurations</a></h5>
<div class="paragraph">
<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>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 href="#webapp-context-attributes">Other Configuration</a> another helpful webapp facility that Jetty provides for cutting down the time spent analyzing jars.</p>
</div>
<div class="paragraph">
<p>Jetty makes use of the flexibility of Configurations to make JNDI and annotation support pluggable.</p>
</div>
<div class="paragraph">
<p>Firstly, lets look at how Configurations help enable JNDI.</p>
</div>
<div class="sect5">
<h6 id="jndi-configuration-classes"><a class="anchor" href="#jndi-configuration-classes"></a><a class="link" href="#jndi-configuration-classes">Example: JNDI Configurations</a></h6>
<div class="paragraph">
<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>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 5. JNDI Configuration classes</caption>
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/plus/webapp/EnvConfiguration.html">org.eclipse.jetty.plus.webapp.EnvConfiguration</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Creates <code>java:comp/env</code> for the webapp, applies a <code>WEB-INF/jetty-env.xml</code> file</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/plus/webapp/PlusConfiguration.html">org.eclipse.jetty.plus.webapp.PlusConfiguration</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Processes JNDI related aspects of <code>WEB-INF/web.xml</code> and hooks up naming entries</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>These configurations must be added in <em>exactly</em> the order shown above and should be inserted <em>immediately before</em> the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.html">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 href="#jndi">here</a>.</p>
</div>
</div>
<div class="sect5">
<h6 id="_example-annotation-configurations"><a class="anchor" href="#_example-annotation-configurations"></a><a class="link" href="#_example-annotation-configurations">Example: Annotation Configurations</a></h6>
<div class="paragraph">
<p>We need just one extra Configuration class to help provide servlet annotation scanning:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 6. Annotation Configuration classes</caption>
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/annotations.AnnotationConfiguration.html">org.eclipse.jetty.annotations.AnnotationConfiguration</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Scan container and web app jars looking for @WebServlet, @WebFilter,
@WebListener etc</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>The above configuration class must be <em>inserted immediately before</em> the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.html">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 href="#webapp-context-attributes">below.</a></p>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_how-to-set-the-list-of-configurations"><a class="anchor" href="#_how-to-set-the-list-of-configurations"></a><a class="link" href="#_how-to-set-the-list-of-configurations">How to Set the List of Configurations</a></h5>
<div class="paragraph">
<p>You have a number of options for how to make Jetty use a different list of Configurations.</p>
</div>
<div class="sect5">
<h6 id="_setting-the-list-directly-on-the-webappcontext"><a class="anchor" href="#_setting-the-list-directly-on-the-webappcontext"></a><a class="link" href="#_setting-the-list-directly-on-the-webappcontext">Setting the list directly on the WebAppContext</a></h6>
<div class="paragraph">
<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 <em>and</em> annotations:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.base</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/webapps/my-cool-webapp<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">configurationClasses</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.lang.String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.webapp.WebInfConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.webapp.WebXmlConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.webapp.MetaInfConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.webapp.FragmentConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.plus.webapp.EnvConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.plus.webapp.PlusConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.annotations.AnnotationConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.webapp.JettyWebXmlConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Of course, you can also use this method to reduce the Configurations applied to a specific <code>WebAppContext</code>.</p>
</div>
</div>
<div class="sect5">
<h6 id="_setting-the-list-for-all-webapps-via-the-deployer"><a class="anchor" href="#_setting-the-list-for-all-webapps-via-the-deployer"></a><a class="link" href="#_setting-the-list-for-all-webapps-via-the-deployer">Setting the list for all webapps via the Deployer</a></h6>
<div class="paragraph">
<p>If you use the <a href="#deployment-architecture">deployer</a>, you can set up the list of Configuration classes on the <a href="#default-web-app-provider">WebAppProvider</a>.
They will then be applied to each <code>WebAppContext</code> deployed by the deployer:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addBean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DeploymentManager</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.deploy.DeploymentManager</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contexts</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Contexts</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">webappprovider</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addAppProvider</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.deploy.providers.WebAppProvider</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">monitoredDirName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.base</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>/webapps<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">configurationClasses</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.lang.String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.webapp.WebInfConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.webapp.WebXmlConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.webapp.MetaInfConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.webapp.FragmentConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.plus.webapp.EnvConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.plus.webapp.PlusConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.annotations.AnnotationConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.webapp.JettyWebXmlConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="_adding-or-inserting-to-an-existing-list"><a class="anchor" href="#_adding-or-inserting-to-an-existing-list"></a><a class="link" href="#_adding-or-inserting-to-an-existing-list">Adding or inserting to an existing list</a></h6>
<div class="paragraph">
<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>$JETTY_HOME/etc/jetty-plus.xml</code> file from the Jetty distribution:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="comment">&lt;!-- =========================================================== --&gt;</span>
<span class="comment">&lt;!-- Add plus Configuring classes to all webapps for this Server --&gt;</span>
<span class="comment">&lt;!-- =========================================================== --&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.Configuration$ClassList</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setServerDefault</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addAfter</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">afterClass</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>org.eclipse.jetty.webapp.FragmentConfiguration<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.plus.webapp.EnvConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.plus.webapp.PlusConfiguration<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/Configuration.html">org.eclipse.jetty.webapp.Configuration.ClassList</a> class provides these methods for insertion:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">addAfter</dt>
<dd>
<p>Inserts the supplied list of <code>Configuration</code> class names after the given Configuration class name.</p>
</dd>
<dt class="hdlist1">addBefore</dt>
<dd>
<p>Inserts the supplied list of <code>Configuration</code> class names before the given Configuration class name.</p>
</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="webapp-context-attributes"><a class="anchor" href="#webapp-context-attributes"></a><a class="link" href="#webapp-context-attributes">Other Configuration</a></h4>
<div class="sect4">
<h5 id="container-include-jar-pattern"><a class="anchor" href="#container-include-jar-pattern"></a><a class="link" href="#container-include-jar-pattern">org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</a></h5>
<div class="paragraph">
<p>This is a <a href="#context_attributes">context attribute</a> that can be set on <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html">an org.eclipse.jetty.webapp.WebAppContext</a> to control which parts of the <em>container&#8217;s</em> classpath should be processed for things like annotations, <code>META-INF/resources</code>, <code>META-INF/web-fragment.xml</code> and <code>tlds</code> inside <code>META-INF</code>.</p>
</div>
<div class="paragraph">
<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>$JETTY_HOME/lib</code> directory.
The libraries contain annotations and therefore must be scanned.</p>
</div>
<div class="paragraph">
<p>The value of this attribute is a regexp that defines which <em>jars</em> and <em>class directories</em> from the container&#8217;s classpath should be examined.</p>
</div>
<div class="paragraph">
<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>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setAttribute</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>.*/foo-[^/]*\.jar$|.*/bar-[^/]*\.jar$|.*/classes/.*<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that the order of the patterns defines the ordering of the scanning of the jars or class directories.</p>
</div>
</div>
<div class="sect4">
<h5 id="web-inf-include-jar-pattern"><a class="anchor" href="#web-inf-include-jar-pattern"></a><a class="link" href="#web-inf-include-jar-pattern">org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</a></h5>
<div class="paragraph">
<p>Similarly to the previous <a href="#context_attributes">context attribute</a>, this attribute controls which jars are processed for things like annotations, <code>META-INF/resources</code>, <code>META-INF/web-fragment.xml</code> and <code>tlds</code> in <code>META-INF</code>.
However, this attribute controls which jars from the <em>webapp&#8217;s</em> classpath (usually <code>WEB-INF/lib</code>) are processed.
This can be particularly useful when you have dozens of jars in <code>WEB-INF/lib</code>, but you know that only a few need to be scanned.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example in a xml file of a pattern that matches any jar that starts with <code>spring-</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setAttribute</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>.*/spring-[^/]*\.jar$<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that the order of the patterns defines the ordering of the scanning of jar files.</p>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="static-content-deployment"><a class="anchor" href="#static-content-deployment"></a><a class="link" href="#static-content-deployment">Configuring Static Content Deployment</a></h3>
<div class="paragraph">
<p>To serve purely static content, the Jetty Deployment Descriptor XML concepts and the internal <code>ResourceHandler</code> can be used.
Create a file called <code>scratch.xml</code> in the <code>${jetty.base}/webapps</code> directory and paste the following file contents in it.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.handler.ContextHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/scratch<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">handler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.handler.ResourceHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
   <span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">resourceBase</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/home/scratch<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">directoriesListed</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This is a very basic setup for serving static files.
For advanced static file serving, use the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlet/DefaultServlet.html">DefaultServlet</a>.</p>
</div>
</div>
<div class="sect2">
<h3 id="deployment-architecture"><a class="anchor" href="#deployment-architecture"></a><a class="link" href="#deployment-architecture">Deployment Architecture</a></h3>
<div class="paragraph">
<p>Jetty is built around an extensible Deployment Manager architecture complete with formal LifeCycle for Web Applications going through it.</p>
</div>
<div class="paragraph">
<p>For Jetty to serve content (static or dynamic), a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ContextHandler.html">ContextHandler</a> needs to be configured and added to Jetty in the appropriate location.
A pluggable <code>DeploymentManager</code> exists to make this process easier.
The Jetty distribution contains example <code>DeploymentManager</code> configurations to deploy WAR files found in a directory to Jetty, and to deploy Jetty context xml files into Jetty as well.</p>
</div>
<div class="paragraph">
<p>The <code>DeploymentManager</code> is the heart of the typical webapp deployment mechanism; it operates as a combination of an Application LifeCycle Graph, Application Providers that find and provide Applications into the Application LifeCycle Graph, and a set of bindings in the graph that control the deployment process.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="Jetty_DeployManager_DeploymentManager_Roles.png" alt="image" width="195"></span></p>
</div>
<div class="sect3">
<h4 id="udm-application-providers"><a class="anchor" href="#udm-application-providers"></a><a class="link" href="#udm-application-providers">Application Providers</a></h4>
<div class="paragraph">
<p>Before Jetty deploys an application, an <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/AppProvider.html"><code>AppProvider</code></a> identifies the App and then provides it to the <code>DeploymentManager</code>.
The main <code>AppProvider</code> with the Jetty distribution is the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/providers/WebAppProvider.html"><code>WebAppProvider</code>.</a></p>
</div>
</div>
<div class="sect3">
<h4 id="udm-application-lifecycle-graph"><a class="anchor" href="#udm-application-lifecycle-graph"></a><a class="link" href="#udm-application-lifecycle-graph">Application LifeCycle Graph</a></h4>
<div class="paragraph">
<p>The core feature of the <code>DeploymentManager</code> is the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/AppLifeCycle.html">Application LifeCycle Graph</a>.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="Jetty_DeployManager_AppLifeCycle-1.png" alt="image" width="340"></span></p>
</div>
<div class="paragraph">
<p>The nodes and edges of this graph are pre-defined in Jetty along the most common actions and states found.
These nodes and edges are not hardcoded; they can be adjusted and added to depending on need (for example, any complex requirements for added workflow, approvals, staging, distribution, coordinated deploys for a cluster or cloud, etc.).</p>
</div>
<div class="paragraph">
<p>New applications enter this graph at the Undeployed node, and the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/DeploymentManager.html#requestAppGoal(org.eclipse.jetty.deploy.App"><code>java.lang.String DeploymentManager.requestAppGoal(App,String)</code></a> method pushes them through the graph.</p>
</div>
</div>
<div class="sect3">
<h4 id="udm-lifecycle-bindings"><a class="anchor" href="#udm-lifecycle-bindings"></a><a class="link" href="#udm-lifecycle-bindings">LifeCycle Bindings</a></h4>
<div class="paragraph">
<p>A set of default <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/AppLifeCycle.Binding.html"><code>AppLifeCycle.Bindings</code></a> defines standard behavior, and handles deploying, starting, stopping, and undeploying applications.
If desired, custom <code>AppLifeCycle.Bindings</code> can be written and assigned anywhere on the Application LifeCycle graph.</p>
</div>
<div class="paragraph">
<p>Examples of new <code>AppLifeCycle.Binding</code> implementations that can be developed include:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Validating the incoming application.</p>
</li>
<li>
<p>Preventing the deployment of known forbidden applications.</p>
</li>
<li>
<p>Submitting the installation to an application auditing service in a corporate environment.</p>
</li>
<li>
<p>Distributing the application to other nodes in the cluster or cloud.</p>
</li>
<li>
<p>Emailing owner/admin of change of state of the application.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>There are four default bindings:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/bindings/StandardDeployer.html"><code>StandardDeployer</code></a> — Deploys the ContextHandler into Jetty in the appropriate place.</p>
</li>
<li>
<p><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/bindings/StandardStarter.html"><code>StandardStarter</code></a> — Sets the ContextHandler to started and start accepting incoming requests.</p>
</li>
<li>
<p><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/bindings/StandardStopper.html"><code>StandardStopper</code></a> — Stops the ContextHandler and stops accepting incoming requests.</p>
</li>
<li>
<p><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/bindings/StandardUndeployer.html"><code>StandardUndeployer</code></a> — Removes the ContextHandler from Jetty.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p><span class="image"><img src="Jetty_DeployManager_DefaultAppLifeCycleBindings.png" alt="image" width="851"></span></p>
</div>
<div class="paragraph">
<p>A fifth, non-standard binding, called <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/bindings/DebugBinding.html">DebugBinding</a>, is also available for debugging reasons; it logs the various transitions through the Application LifeCycle.</p>
</div>
<div class="sect4">
<h5 id="_using-globalwebappconfigbinding"><a class="anchor" href="#_using-globalwebappconfigbinding"></a><a class="link" href="#_using-globalwebappconfigbinding">Using GlobalWebappConfigBinding</a></h5>
<div class="paragraph">
<p>In addition to the LifeCycle bindings discussed above, there is also the <a href="https://www.eclipse.org/jetty/javadoc/current/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.html"><code>GlobalWebappConfigBinding</code></a> which, when added to the <code>DeploymentManager</code> will apply an additional configuration XML file to each webapp that it deploys.
This can useful when setting server or system classes, or when defining <a href="#override-web-xml">override descriptors.</a>
This configuration XML file will be <em>in addition to</em> any context XML file that exists for the webapp; it will be applied <em>after</em> any context XML files but <em>before</em> the webapp is started.
The format for the XML file is the same as any context XML file and can be used to same parameters for a webapp.</p>
</div>
<div class="paragraph">
<p>To use this binding, you can either modify the existing <code>jetty-deploy.xml</code> which comes with the Jetty distribution (be sure to <a href="#startup-base-and-home">copy it to your $JETTY_BASE/etc directory first</a>), or by <a href="#custom-modules">creating a new module</a> file which calls to an additional XML file.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addLifeCycleBinding</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.deploy.bindings.GlobalWebappConfigBinding</span><span class="delimiter">&quot;</span></span> <span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jettyXml</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>/etc/global-webapp-config.xml<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="default-web-app-provider"><a class="anchor" href="#default-web-app-provider"></a><a class="link" href="#default-web-app-provider">Understanding the Default WebAppProvider</a></h4>
<div class="paragraph">
<p>The <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/providers/WebAppProvider.html">WebAppProvider</a> is used for the deployment of Web Applications packaged as WAR files, expanded as a directory, or declared in a <a href="#deployable-descriptor-file">Jetty Deployable Descriptor XML File</a>.
It supports hot (re)deployment.</p>
</div>
<div class="paragraph">
<p>The basic operation of the <code>WebAppProvider</code> is to periodically scan a directory for deployables.
In the standard Jetty Distribution, this is configured in the <code>${jetty.home}/etc/jetty-deploy.xml</code> file.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addBean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DeploymentManager</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.deploy.DeploymentManager</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contexts</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Contexts</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">webappprovider</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addAppProvider</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.deploy.providers.WebAppProvider</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">monitoredDirName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>/webapps<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">defaultsDescriptor</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>/etc/webdefault.xml<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">scanInterval</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>1<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">extractWars</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The above configuration will create a <code>DeploymentManager</code> tracked as a Server LifeCycle Bean, with the following configuration.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">contexts</dt>
<dd>
<p>A passed in reference to the HandlerContainer into which the discovered webapps are deployed.
This is normally a reference that points to the <code>id="Contexts"</code> found in the <code>${jetty.home}/etc/jetty.xml</code> file, which itself is an instance of <code>ContextHandlerCollection</code>.</p>
</dd>
<dt class="hdlist1">monitoredDirName</dt>
<dd>
<p>The file path or URL to the directory to scan for web applications.</p>
<div class="literalblock">
<div class="content">
<pre>Scanning follows these rules:</pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>A base directory must exist.</p>
</li>
<li>
<p>Hidden Files (starting with <code>"."</code>) are ignored.</p>
</li>
<li>
<p>Directories with names ending in <code>".d"</code> are ignored.</p>
</li>
<li>
<p>Common CVS directories <code>"CVS"</code> and <code>"CVSROOT"</code> are ignored.</p>
</li>
<li>
<p>Any <code>*.war</code> files are considered <a href="#automatic-webapp-deployment">automatic deployables</a>.</p>
</li>
<li>
<p>Any <code>*.xml</code> files are considered <a href="#deployable-descriptor-file">context descriptor deployables</a>.</p>
</li>
<li>
<p>In the special case where both a WAR file and XML file exists for same base name, the XML file is assumed to configure and reference the WAR file (see <a href="#configuring-specific-webapp-deployment">Configuring a Specific Web Application Deployment</a>).
Since jetty-9.2.7, if either the WAR file or its corresponding XML file changes, the webapp will be redeployed.</p>
</li>
<li>
<p>A directory is considered to be deployable.</p>
</li>
<li>
<p>In the special case where both a Directory and WAR file of the same name exists, the WAR file is assumed to be an automatic deployable.</p>
</li>
<li>
<p>In the special case where both a Directory and XML file of the same name exists, the XML file is assumed to configure and reference the Directory.</p>
</li>
<li>
<p>All other directories are subject to automatic deployment.</p>
</li>
<li>
<p>If automatic deployment is used, and the special filename <code>root.war/ROOT.war</code> or directory name <code>root/ROOT</code> will result in a deployment to the <code>"/"</code> context path.</p>
</li>
</ol>
</div>
</dd>
<dt class="hdlist1">defaultsDescriptor</dt>
<dd>
<p>Specifies the default Servlet web descriptor to use for all Web Applications.
The intent of this descriptor is to include common configuration for the Web Application before the Web Application&#8217;s own <code>/WEB-INF/web.xml</code> is applied.
The <code>${jetty.home}/etc/webdefault.xml</code> that comes with the Jetty distribution controls the configuration of the JSP and Default servlets, along with MIME-types and other basic metadata.</p>
</dd>
<dt class="hdlist1">scanInterval</dt>
<dd>
<p>The period in seconds between sweeps of the <code>monitoredDirName</code> for changes: new contexts to deploy, changed contexts to redeploy, or removed contexts to undeploy.</p>
</dd>
<dt class="hdlist1">extractWars</dt>
<dd>
<p>If parameter is true, any packed WAR or zip files are first extracted to a temporary directory before being deployed.
This is advisable if there are uncompiled JSPs in the web apps.</p>
</dd>
<dt class="hdlist1">parentLoaderPriority</dt>
<dd>
<p>Parameter is a boolean that selects whether the standard Java <a href="#jetty-classloading">parent first delegation</a> is used or the <a href="#jetty-classloading">servlet specification webapp classloading priority</a>.
The latter is the default.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect2">
<h3 id="quickstart-webapp"><a class="anchor" href="#quickstart-webapp"></a><a class="link" href="#quickstart-webapp">Quickstart Webapps</a></h3>
<div class="paragraph">
<p>The auto discovery features of the Servlet specification can make deployments slow and uncertain.
Auto discovery of Web Application configuration can be useful during the development of a webapp as it allows new features and frameworks to be enabled simply by dropping in a jar file.
However, for deployment, the need to scan the contents of many jars can have a significant impact of the start time of a webapp.</p>
</div>
<div class="paragraph">
<p>With the release of Jetty 9.2, a quickstart module was included which allows a webapp to be pre-scanned and preconfigured.
This means that all the scanning is done prior to deployment and all configuration is encoded into an effective <code>web.xml</code>, called <code>WEB-INF/quickstart-web.xml</code>, which can be inspected to understand what will be deployed before deploying.
Not only does the <code>quickstart-web.xml</code> contain all the discovered Servlets, Filters and Constraints, but it also encodes as context parameters all discovered:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>ServletContainerInitializers</p>
</li>
<li>
<p>HandlesTypes classes</p>
</li>
<li>
<p>Taglib Descriptors</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>With the quickstart mechanism, Jetty is able to entirely bypass all scanning and discovery modes and start a webapp in a predictable and fast way.
Tests have shown that webapps that took many seconds to scan and deploy can now be deployed in a few hundred milliseconds.</p>
</div>
<div class="sect3">
<h4 id="_setting-up-quickstart"><a class="anchor" href="#_setting-up-quickstart"></a><a class="link" href="#_setting-up-quickstart">Setting up Quickstart</a></h4>
<div class="sect4">
<h5 id="_prerequisites"><a class="anchor" href="#_prerequisites"></a><a class="link" href="#_prerequisites">Prerequisites</a></h5>
<div class="sect5">
<h6 id="_jetty-distribution-2"><a class="anchor" href="#_jetty-distribution-2"></a><a class="link" href="#_jetty-distribution-2">Jetty Distribution</a></h6>
<div class="paragraph">
<p>In a standard Jetty distribution the quickstart module can be configured with the following command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ java -jar $JETTY_HOME/start.jar --add-to-start=quickstart</code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="_embedded"><a class="anchor" href="#_embedded"></a><a class="link" href="#_embedded">Embedded</a></h6>
<div class="paragraph">
<p>In a Maven project you add a dependency on the artifact <code>jetty-quickstart</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-quickstart<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>10.0.10<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_configuration"><a class="anchor" href="#_configuration"></a><a class="link" href="#_configuration">Configuration</a></h5>
<div class="paragraph">
<p>Webapps need to be instances of <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/quickstart/QuickStartWebApp.html"><code>org.eclipse.jetty.quickstart.QuickStartWebApp</code></a> rather than the normal <code>org.eclipse.jetty.webapp.WebAppContext</code>.</p>
</div>
<div class="paragraph">
<p><code>org.eclipse.jetty.quickstart.QuickStartWebApp</code> instances offer the same setters as the familiar <code>org.eclipse.jetty.webapp.WebAppContext</code>, with the addition of:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">autoPreconfigure</dt>
<dd>
<p>(true/false).
If true, the first time the webapp is run, the WEB-INF/quickstart-web.xml is generated BEFORE the webapp is deployed.
Subsequent runs use the previously generated quickstart file.</p>
</dd>
<dt class="hdlist1">originAttribute</dt>
<dd>
<p>The name of an attribute to insert into the generated elements in quickstart-web.xml that gives the origin of the element.
By default it is <code>origin</code>.</p>
</dd>
<dt class="hdlist1">generateOrigin</dt>
<dd>
<p>(true/false).
By default it is <code>false</code>.
If true, the origin attribute will be inserted into each element in quickstart-web.xml.
Note that origin attributes will also be generated if debug log level is enabled.</p>
</dd>
</dl>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
If you are using Spring-Boot you must set <code>generateOrigin</code> to true.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>The origin is either a descriptor eg web.xml,web-fragment.xml,override-web.xml file, or an annotation eg @WebServlet.
For xml validation each attribute must be unique, and therefore an integer counter is appended to each value.
Some examples of elements with origin attribute information are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;listener</span> <span class="attribute-name">origin</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DefaultsDescriptor(file:///path/to/distro/etc/webdefault.xml):21</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;listener</span> <span class="attribute-name">origin</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">WebDescriptor(file:///path/to/base/webapps/test-spec/WEB-INF/web.xml):22</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;servlet-class</span> <span class="attribute-name">origin</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">FragmentDescriptor(jar:file:///path/to/base/webapps/test-spec/WEB-INF/lib/test-web-fragment.jar!/META-INF/web-fragment.xml):23</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;servlet-class</span> <span class="attribute-name">origin</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">@WebServlet(com.acme.test.TestServlet):24</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span></code></pre>
</div>
</div>
<div class="sect5">
<h6 id="_in-xml"><a class="anchor" href="#_in-xml"></a><a class="link" href="#_in-xml">In XML</a></h6>
<div class="paragraph">
<p>If a web application already has a context xml file, eg <code>webapps/myapp.xml</code> file, simply change the class in the <code>Configure</code> element.
Otherwise, create a context xml file with the following information (in addition to the usual setting of contextPath, war etc):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.quickstart.QuickStartWebApp</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">autoPreconfigure</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="_in-code"><a class="anchor" href="#_in-code"></a><a class="link" href="#_in-code">In Code</a></h6>
<div class="paragraph">
<p>Create an instance of <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/quickstart/QuickStartWebApp.html"><code>org.eclipse.jetty.quickstart.QuickStartWebApp</code></a> rather than the normal <code>org.eclipse.jetty.webapp.WebAppContext</code>. You then use the QuickStartWebApp instance in exactly the same way that you would a WebAppContext.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s a snippet:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"> QuickStartWebApp webapp = <span class="keyword">new</span> QuickStartWebApp();
webapp.setAutoPreconfigure(<span class="predefined-constant">true</span>);</code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="_pre-generating-the-quickstart-web-xml-file"><a class="anchor" href="#_pre-generating-the-quickstart-web-xml-file"></a><a class="link" href="#_pre-generating-the-quickstart-web-xml-file">Pre-generating the quickstart-web.xml file</a></h6>
<div class="paragraph">
<p>Rather than use the <code>autoPreconfigure</code> feature of the QuickStartWebApp - which lazily generates the <code>quickstart-web.xml</code> file - you can eagerly pre-generate it for an existing war by invoking as a main class <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/quickstart/PreconfigureQuickStartWar.html"><code>org.eclipse.jetty.quickstart.PreconfigureQuickStartWar</code></a>.
Note that you will need to provide all necessary jetty jars on the command line classpath.
This will unpack the war if necessary, and create the <code>quickstart-web.xml</code> before the first deployment:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ java -cp [jetty classpath] org.eclipse.jetty.quickstart.PreconfigureQuickStartWar myapp.war</code></pre>
</div>
</div>
<div class="paragraph">
<p>Run the class with no arguments to see other runtime options.</p>
</div>
<div class="paragraph">
<p>Alternatively, you could use the <a href="#get-up-and-running">Jetty Maven Plugin</a> goal <a href="#jetty-effective-web-xml"><code>jetty:effective-web-xml</code></a>: this will generate quickstart information, but print it to stderr.
The goal provides a configuration option to save the output to a file, which you can then copy into your webapp&#8217;s WEB-INF dir.
Note that as the Jetty Maven Plugin is a general tool for running webapps, it may have more jars on its classpath than are needed by your application, and thus may generate extra quickstart information: we recommend that you use this goal only as a quick guide to the type of information that quickstart generates.</p>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_avoiding-tld-scans-with-precompiled-jsps"><a class="anchor" href="#_avoiding-tld-scans-with-precompiled-jsps"></a><a class="link" href="#_avoiding-tld-scans-with-precompiled-jsps">Avoiding TLD Scans with precompiled JSPs</a></h4>
<div class="paragraph">
<p>Of course precompiling JSPs is an excellent way to improve the start time of a web application.
As of Jetty 9.2 the Apache Jasper JSP implementation has been used and has been augmented to allow the TLD scan to be skipped.
This can be done by adding a <code>context-param</code> to the <code>web.xml</code> file (this is done automatically by the Jetty Maven JSPC plugin):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;context-param&gt;</span>
<span class="tag">&lt;param-name&gt;</span>org.eclipse.jetty.jsp.precompiled<span class="tag">&lt;/param-name&gt;</span>
<span class="tag">&lt;param-value&gt;</span>true<span class="tag">&lt;/param-value&gt;</span>
<span class="tag">&lt;/context-param&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_bypassing-start-jar"><a class="anchor" href="#_bypassing-start-jar"></a><a class="link" href="#_bypassing-start-jar">Bypassing start.jar</a></h4>
<div class="paragraph">
<p>The Jetty <code>start.jar</code> mechanism is a very powerful and flexible mechanism for constructing a <code>classpath</code> and executing a configuration encoded in Jetty XML format.
However, this mechanism does take some time to build the <code>classpath</code>.
The start.jar mechanism can be bypassed by using the <code>–dry-run</code> option to generate and reuse a complete command line to start Jetty at a later time:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ RUN=$(java -jar $JETTY_HOME/start.jar --dry-run)
$ eval $RUN</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that <code>--dry-run</code> may create a properties file in the temp directory and include it on the generated command line.
If so, then a copy of the temporary properties file should be taken and the command line updated with it&#8217;s new persistent location.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="advanced-embedding"><a class="anchor" href="#advanced-embedding"></a><a class="link" href="#advanced-embedding">Embedding</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="jetty-helloworld"><a class="anchor" href="#jetty-helloworld"></a><a class="link" href="#jetty-helloworld">Jetty Embedded HelloWorld</a></h3>
<div class="paragraph">
<p>This section provides a tutorial that shows how you can quickly develop embedded code against the Jetty API.</p>
</div>
<div class="sect3">
<h4 id="downloading-jars"><a class="anchor" href="#downloading-jars"></a><a class="link" href="#downloading-jars">Downloading the Jars</a></h4>
<div class="paragraph">
<p>Jetty is decomposed into many jars and dependencies to achieve a minimal footprint by selecting the minimal set of jars.
Typically it is best to use something like <a href="#jetty-maven-helloworld">Maven</a> to manage jars, however this tutorial uses an aggregate Jar that contains all of the required Jetty classes in one Jar.
You can manually download the aggregate <a href="https://repo1.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/10.0.10/jetty-all-10.0.10-uber.jar"><code>jetty-all.jar</code></a> using <code>curl</code> or a browser.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The central Maven repository has started to aggressively reject/deny access to the repository from the <code>wget</code> command line tool (due to abusive use of the tool by some groups).
The administrators of the central maven repository have stated that the recommended command line download tool is now curl.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
The <code>jetty-all</code> jar referenced in this section is for example purposes only and should not be used outside of this context.
Please consider using <a href="#jetty-maven-helloworld">Maven</a> to manage your project dependencies.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>Use curl as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; mkdir Demo
&gt; cd Demo
&gt; curl -o jetty-all-uber.jar https://repo1.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/10.0.10/jetty-all-10.0.10-uber.jar</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="writing-helloworld-example"><a class="anchor" href="#writing-helloworld-example"></a><a class="link" href="#writing-helloworld-example">Writing a HelloWorld Example</a></h4>
<div class="paragraph">
<p>The <a href="#embedding">Embedding Jetty</a> section contains many examples of writing against the Jetty API.
This tutorial uses a simple HelloWorld handler with a main method to run the server.
You can either <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded/HelloWorld.java">download</a> or create in an editor the file <code>HelloWorld.java</code> with the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/jetty-helloworld.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/HelloWorld.java<span class="type">[]</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="compiling-helloworld-example"><a class="anchor" href="#compiling-helloworld-example"></a><a class="link" href="#compiling-helloworld-example">Compiling the HelloWord example</a></h4>
<div class="paragraph">
<p>The following command compiles the HelloWorld class:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; mkdir classes
&gt; javac -d classes -cp jetty-all-uber.jar HelloWorld.java</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="running-handler-and-server"><a class="anchor" href="#running-handler-and-server"></a><a class="link" href="#running-handler-and-server">Running the Handler and Server</a></h4>
<div class="paragraph">
<p>The following command runs the HelloWorld example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -cp classes:jetty-all-uber.jar org.eclipse.jetty.demos.HelloWorld</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can now point your browser at <a href="http://localhost:8080/">http://localhost:8080</a> to see your hello world page.</p>
</div>
</div>
<div class="sect3">
<h4 id="next-steps"><a class="anchor" href="#next-steps"></a><a class="link" href="#next-steps">Next Steps</a></h4>
<div class="paragraph">
<p>To learn more about Jetty, take these next steps:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Follow the examples in <a href="#embedding-jetty">Embedding Jetty</a> to better understand the jetty APIs.</p>
</li>
<li>
<p>Explore the complete <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/">Jetty javadoc</a></p>
</li>
<li>
<p>Consider using <a href="#maven-and-jetty">Jetty and Maven</a> to manage your Jars and dependencies.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect2">
<h3 id="embedding-jetty"><a class="anchor" href="#embedding-jetty"></a><a class="link" href="#embedding-jetty">Embedding Jetty</a></h3>
<div class="paragraph">
<p>Jetty has a slogan, "<em>Don&#8217;t deploy your application in Jetty, deploy Jetty in your application!</em>"
What this means is that as an alternative to bundling your application as a standard WAR to be deployed in Jetty, Jetty is designed to be a software component that can be instantiated and used in a Java program just like any POJO.
Put another way, running Jetty in embedded mode means putting an HTTP module into your application, rather than putting your application into an HTTP server.</p>
</div>
<div class="paragraph">
<p>This tutorial takes you step-by-step from the simplest Jetty server instantiation to running multiple web applications with standards-based deployment descriptors.
The source for most of these examples is part of the standard Jetty project.</p>
</div>
<div class="sect3">
<h4 id="_overview"><a class="anchor" href="#_overview"></a><a class="link" href="#_overview">Overview</a></h4>
<div class="paragraph">
<p>To embed a Jetty server the following steps are typical and are illustrated by the examples in this tutorial:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Create a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/Server.html">Server</a> instance.</p>
</li>
<li>
<p>Add/Configure <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/Connector.html">Connectors</a>.</p>
</li>
<li>
<p>Add/Configure <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/Handler.html">Handlers</a> and/or <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ContextHandler.html">Contexts</a> and/or <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/Servlet.html">Servlets</a>.</p>
</li>
<li>
<p>Start the Server.</p>
</li>
<li>
<p>Wait on the server or do something else with your thread.</p>
</li>
</ol>
</div>
</div>
<div class="sect3">
<h4 id="_creating-the-server"><a class="anchor" href="#_creating-the-server"></a><a class="link" href="#_creating-the-server">Creating the Server</a></h4>
<div class="paragraph">
<p>The following code from SimplestServer.java instantiates and runs the simplest possible Jetty server:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/SimplestServer.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This runs an HTTP server on port 8080. It is not a very useful server as it has no handlers, and thus returns a 404 error for every request.</p>
</div>
</div>
<div class="sect3">
<h4 id="_using-handlers"><a class="anchor" href="#_using-handlers"></a><a class="link" href="#_using-handlers">Using Handlers</a></h4>
<div class="paragraph">
<p>To produce a response to a request, Jetty requires that you set a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/Handler.html">Handler</a> on the server.
A handler may:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Examine/modify the HTTP request.</p>
</li>
<li>
<p>Generate the complete HTTP response.</p>
</li>
<li>
<p>Call another Handler (see <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/HandlerWrapper.html"><code>HandlerWrapper</code></a>).</p>
</li>
<li>
<p>Select one or many Handlers to call (see <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/HandlerCollection.html"><code>HandlerCollection</code></a>).</p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="_helloworld-handler"><a class="anchor" href="#_helloworld-handler"></a><a class="link" href="#_helloworld-handler">HelloWorld Handler</a></h5>
<div class="paragraph">
<p>The following code based on HelloHandler.java shows a simple hello world handler:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/HelloHandler.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The parameters passed to the handle method are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>target</code> – the target of the request, which is either a URI or a name from a named dispatcher.</p>
</li>
<li>
<p><code>baseRequest</code> – the Jetty mutable request object, which is always unwrapped.</p>
</li>
<li>
<p><code>request</code> – the immutable request object, which may have been wrapped by a filter or servlet.</p>
</li>
<li>
<p><code>response</code> – the response, which may have been wrapped by a filter or servlet.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The handler sets the response status, content-type, and marks the request as handled before it generates the body of the response using a writer.</p>
</div>
</div>
<div class="sect4">
<h5 id="_running-helloworldhandler"><a class="anchor" href="#_running-helloworldhandler"></a><a class="link" href="#_running-helloworldhandler">Running HelloWorldHandler</a></h5>
<div class="paragraph">
<p>To allow a Handler to handle HTTP requests, you must add it to a Server instance.
The following code from OneHandler.java shows how a Jetty server can use the HelloWorld handler:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneHandler.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>One or more handlers do all request handling in Jetty.
Some handlers select other specific handlers (for example, a <code>ContextHandlerCollection</code> uses the context path to select a <code>ContextHandler</code>); others use application logic to generate a response (for example, the <code>ServletHandler</code> passes the request to an application Servlet), while others do tasks unrelated to generating the response (for example, <code>RequestLogHandler</code> or <code>StatisticsHandler</code>).</p>
</div>
<div class="paragraph">
<p>Later sections describe how you can combine handlers like aspects.
You can see some of the handlers available in Jetty in the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/package-summary.html">org.eclipse.jetty.server.handler</a> package.</p>
</div>
</div>
<div class="sect4">
<h5 id="_handler-collections-and-wrappers"><a class="anchor" href="#_handler-collections-and-wrappers"></a><a class="link" href="#_handler-collections-and-wrappers">Handler Collections and Wrappers</a></h5>
<div class="paragraph">
<p>Complex request handling is typically built from multiple Handlers that you can combine in various ways.
Jetty has several implementations of the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/HandlerContainer.html"><code>HandlerContainer</code></a> interface:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/HandlerCollection.html"><code>HandlerCollection</code></a></dt>
<dd>
<p>Holds a collection of other handlers and calls each handler in order.
This is useful for combining statistics and logging handlers with the handler that generates the response.</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/HandlerList.html"><code>HandlerList</code></a></dt>
<dd>
<p>A Handler Collection that calls each handler in turn until either an exception is thrown, the response is committed or the <code>request.isHandled()</code> returns true.
You can use it to combine handlers that conditionally handle a request, such as calling multiple contexts until one matches a virtual host.</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/HandlerWrapper.html"><code>HandlerWrapper</code></a></dt>
<dd>
<p>A Handler base class that you can use to daisy chain handlers together in the style of aspect-oriented programming.
For example, a standard web application is implemented by a chain of a context, session, security and servlet handlers.</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ContextHandlerCollection.html"><code>ContextHandlerCollection</code></a></dt>
<dd>
<p>A specialized <code>HandlerCollection</code> that uses the longest prefix of the request URI (the <code>contextPath</code>) to select a contained <code>ContextHandler</code> to handle the request.</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_scoped-handlers"><a class="anchor" href="#_scoped-handlers"></a><a class="link" href="#_scoped-handlers">Scoped Handlers</a></h5>
<div class="paragraph">
<p>Much of the standard Servlet container in Jetty is implemented with <code>HandlerWrappers</code> that daisy chain handlers together: <code>ContextHandler</code> to <code>SessionHandler</code> to <code>SecurityHandler</code> to <code>ServletHandler</code>.
However, because of the nature of the servlet specification, this chaining cannot be a pure nesting of handlers as the outer handlers sometimes need information that the inner handlers process.
For example, when a <code>ContextHandler</code> calls some application listeners to inform them of a request entering the context, it must already know which servlet the <code>ServletHandler</code> will dispatch the request to so that the <code>servletPath</code> method returns the correct value.</p>
</div>
<div class="paragraph">
<p>The <code>HandlerWrapper</code> is specialized to the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ScopedHandler.html"><code>ScopedHandler</code></a> abstract class, which supports a daisy chain of scopes.
For example if a <code>ServletHandler</code> is nested within a <code>ContextHandler</code>, the order and nesting of execution of methods is:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>Server.handle(...)
ContextHandler.doScope(...)
ServletHandler.doScope(...)
ContextHandler.doHandle(...)
ServletHandler.doHandle(...)
SomeServlet.service(...)</pre>
</div>
</div>
<div class="paragraph">
<p>Thus when the <code>ContextHandler</code> handles the request, it does so within the scope the <code>ServletHandler</code> has established.</p>
</div>
</div>
<div class="sect4">
<h5 id="_resource-handler"><a class="anchor" href="#_resource-handler"></a><a class="link" href="#_resource-handler">Resource Handler</a></h5>
<div class="paragraph">
<p>The <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/FileServer.html">FileServer example</a> shows how you can use a <code>ResourceHandler</code> to serve static content from the current working directory:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServer.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Notice that a <code>HandlerList</code> is used with the <code>ResourceHandler</code> and a <code>DefaultHandler</code>, so that the <code>DefaultHandler</code> generates a good 404 response for any requests that do not match a static resource.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_embedding-connectors"><a class="anchor" href="#_embedding-connectors"></a><a class="link" href="#_embedding-connectors">Embedding Connectors</a></h4>
<div class="paragraph">
<p>In the previous examples, the Server instance is passed a port number and it internally creates a default instance of a Connector that listens for requests on that port.
However, often when embedding Jetty it is desirable to explicitly instantiate and configure one or more Connectors for a Server instance.</p>
</div>
<div class="sect4">
<h5 id="_one-connector"><a class="anchor" href="#_one-connector"></a><a class="link" href="#_one-connector">One Connector</a></h5>
<div class="paragraph">
<p>The following example, <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/OneConnector.html">OneConnector.java</a>,
instantiates, configures, and adds a single HTTP connector instance to the server:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneConnector.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>In this example the connector handles the HTTP protocol, as that is the default for the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ServerConnector.html"><code>ServerConnector</code></a> class.</p>
</div>
</div>
<div class="sect4">
<h5 id="_many-connectors"><a class="anchor" href="#_many-connectors"></a><a class="link" href="#_many-connectors">Many Connectors</a></h5>
<div class="paragraph">
<p>When configuring multiple connectors (for example, HTTP and HTTPS), it may be desirable to share configuration of common parameters for HTTP.
To achieve this you need to explicitly configure the <code>ServerConnector</code> class with <code>ConnectionFactory</code> instances, and provide them with common HTTP configuration.</p>
</div>
<div class="paragraph">
<p>The <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/ManyConnectors.html">ManyConnectors example</a>, configures a server with two <code>ServerConnector</code> instances: the http connector has a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/HttpConnectionFactory.html"><code>HTTPConnectionFactory</code></a> instance; the https connector has a <code>SslConnectionFactory</code> chained to a <code>HttpConnectionFactory</code>.
Both <code>HttpConnectionFactory</code> are configured based on the same <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/HttpConfiguration.html"><code>HttpConfiguration</code></a> instance, however the HTTPS factory uses a wrapped configuration so that a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/SecureRequestCustomizer.html"><code>SecureRequestCustomizer</code></a> can be added.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_embedding-servlets"><a class="anchor" href="#_embedding-servlets"></a><a class="link" href="#_embedding-servlets">Embedding Servlets</a></h4>
<div class="paragraph">
<p><a href="http://en.wikipedia.org/wiki/Java_Servlet">Servlets</a> are the standard way to provide application logic that handles HTTP requests.
Servlets are similar to a Jetty Handler except that the request object is not mutable and thus cannot be modified.
Servlets are handled in Jetty by a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/MinimalServlets.html"><code>ServletHandler</code></a>.
It uses standard path mappings to match a Servlet to a request; sets the requests <code>servletPath</code> and <code>pathInfo</code>; passes the request to the servlet, possibly via Filters to produce a response.</p>
</div>
<div class="paragraph">
<p>The <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/MinimalServlets.html">MinimalServlets example</a> creates a <code>ServletHandler</code> instance and configures a single HelloServlet:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/MinimalServlets.java<span class="type">[]</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_embedding-contexts"><a class="anchor" href="#_embedding-contexts"></a><a class="link" href="#_embedding-contexts">Embedding Contexts</a></h4>
<div class="paragraph">
<p>A <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/OneContext.html"><code>ContextHandler</code></a> is a <code>ScopedHandler</code> that responds only to requests that have a URI prefix that matches the configured context path.
Requests that match the context path have their path methods updated accordingly and the contexts scope is available, which optionally may include:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A <code>Classloader</code> that is set as the Thread context <code>classloader</code> while request handling is in scope.</p>
</li>
<li>
<p>A set of attributes that is available via the <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html"><code>ServletContext</code></a> API.</p>
</li>
<li>
<p>A set of init parameters that is available via the <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html"><code>ServletContext</code></a> API.</p>
</li>
<li>
<p>A base Resource which is used as the document root for static resource requests via the <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html"><code>ServletContext</code></a> API.</p>
</li>
<li>
<p>A set of virtual host names.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The following <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/OneContext.html">OneContext example</a> shows a context being established that wraps the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/HelloHandler.html">HelloHandler</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneContext.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>When many contexts are present, you can embed a <code>ContextHandlerCollection</code> to efficiently examine a request URI to then select the matching <code>ContextHandler</code>(s) for the request.
The <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/ManyContexts.html">ManyContexts example</a> shows how many such contexts you can configure:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyContexts.java<span class="type">[]</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_embedding-servletcontexts"><a class="anchor" href="#_embedding-servletcontexts"></a><a class="link" href="#_embedding-servletcontexts">Embedding ServletContexts</a></h4>
<div class="paragraph">
<p>A <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlet/ServletContextHandler.html"><code>ServletContextHandler</code></a> is a specialization of <code>ContextHandler</code> with support for standard sessions and Servlets.
The following <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/OneServletContext.html">OneServletContext example</a> instantiates a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlet/DefaultServlet.html"><code>DefaultServlet</code></a> to server static content from /tmp/ and a <code>DumpServlet</code> that creates a session and dumps basic details about the request:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneServletContext.java<span class="type">[]</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_embedding-web-applications"><a class="anchor" href="#_embedding-web-applications"></a><a class="link" href="#_embedding-web-applications">Embedding Web Applications</a></h4>
<div class="paragraph">
<p>A <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a> is an extension of a <code>ServletContextHandler</code> that uses the <a href="http://en.wikipedia.org/wiki/WAR_%28Sun_file_format%29">standard layout</a> and web.xml to configure the servlets, filters and other features from a web.xml and/or annotations.
The following <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/embedded/OneWebApp.html">OneWebApp example</a> configures the Jetty test webapp.
Web applications can use resources the container provides, and in this case a <code>LoginService</code> is needed and also configured:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java<span class="type">[]</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_like-jetty-xml"><a class="anchor" href="#_like-jetty-xml"></a><a class="link" href="#_like-jetty-xml">Like Jetty XML</a></h4>
<div class="paragraph">
<p>The typical way to configure an instance of the Jetty server is via <code>jetty.xml</code> and associated configuration files.
However the Jetty XML configuration format is just a simple rendering of what you can do in code; it is very simple to write embedded code that does precisely what the jetty.xml configuration does.
The <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java">LikeJettyXml example</a> following renders in code the behavior obtained from the configuration files:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty.xml">jetty.xml</a></p>
</li>
<li>
<p><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-jmx/src/main/config/etc/jetty-jmx.xml">jetty-jmx.xml</a></p>
</li>
<li>
<p><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-http.xml">jetty-http.xml</a></p>
</li>
<li>
<p><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-https.xml">jetty-https.xml</a></p>
</li>
<li>
<p><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-deploy/src/main/config/etc/jetty-deploy.xml">jetty-deploy.xml</a></p>
</li>
<li>
<p><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-stats.xml">jetty-stats.xml</a></p>
</li>
<li>
<p><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-requestlog.xml">jetty-requestlog.xml</a></p>
</li>
<li>
<p><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-server/src/main/config/etc/jetty-lowresources.xml">jetty-lowresources.xml</a></p>
</li>
<li>
<p><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/test-realm.xml">test-realm.xml</a></p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedding-jetty.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java<span class="type">[]</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="embedded-examples"><a class="anchor" href="#embedded-examples"></a><a class="link" href="#embedded-examples">Embedded Examples</a></h3>
<div class="paragraph">
<p>Jetty has a rich history of being embedded into a wide variety of applications.
In this section we will walk you through a number of our simple examples under our embedded-jetty-examples project in our git repository.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
These files are pulled directly from our git repository when this document is generated.
If the line numbers do not line up feel free to fix this documentation in github and give us a pull request, or at least open an issue to notify us of the discrepancy.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect3">
<h4 id="embedded-file-server"><a class="anchor" href="#embedded-file-server"></a><a class="link" href="#embedded-file-server">Simple File Server</a></h4>
<div class="paragraph">
<p>This example shows how to create a simple file server in Jetty.
It is perfectly suitable for test cases where you need an actual web server to obtain a file from, it could easily be configured to serve files from a directory under <code>src/test/resources</code>.
Note that this does not have any logic for caching of files, either within the server or setting the appropriate headers on the response.
It is simply a few lines that illustrate how easy it is to serve out some files.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/examples/embedded-file-server.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServer.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_run-it"><a class="anchor" href="#_run-it"></a><a class="link" href="#_run-it">Run it!</a></h5>
<div class="paragraph">
<p>After you have started things up you should be able to navigate to <a href="http://localhost:8080/index.html" class="bare">http://localhost:8080/index.html</a> (assuming one is in the resource base directory) and you are good to go.</p>
</div>
</div>
<div class="sect4">
<h5 id="_maven-coordinates"><a class="anchor" href="#_maven-coordinates"></a><a class="link" href="#_maven-coordinates">Maven Coordinates</a></h5>
<div class="paragraph">
<p>To use this example in your project you will need the following Maven dependencies declared.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-server<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="embedded-split-file-server"><a class="anchor" href="#embedded-split-file-server"></a><a class="link" href="#embedded-split-file-server">Split File Server</a></h4>
<div class="paragraph">
<p>This example builds on the <a href="#emebedded-file-server">Simple File Server</a> to show how chaining multiple <code>ResourceHandlers</code> together can let you aggregate multiple directories to serve content on a single path and how you can link these together with <code>ContextHandlers</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/examples/embedded-split-file-server.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/SplitFileServer.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_run-it-2"><a class="anchor" href="#_run-it-2"></a><a class="link" href="#_run-it-2">Run it!</a></h5>
<div class="paragraph">
<p>After you have started things up you should be able to navigate to <a href="http://localhost:8090/index.html" class="bare">http://localhost:8090/index.html</a> (assuming one is in the resource base directory) and you are good to go.
Any requests for files will be looked for in the first resource handler, then the second, and so on and so forth.</p>
</div>
</div>
<div class="sect4">
<h5 id="_maven-coordinates-2"><a class="anchor" href="#_maven-coordinates-2"></a><a class="link" href="#_maven-coordinates-2">Maven Coordinates</a></h5>
<div class="paragraph">
<p>To use this example as is in your project you will need the following maven dependencies declared.
We would recommend not using the toolchain dependency in your actual application.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-server<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span>
<span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty.toolchain<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-test-helper<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>2.2<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="embedded-many-connectors"><a class="anchor" href="#embedded-many-connectors"></a><a class="link" href="#embedded-many-connectors">Multiple Connectors</a></h4>
<div class="paragraph">
<p>This example shows how to configure Jetty to use multiple connectors, specifically so it can process both http and https requests.
Since the meat of this example is the server and connector configuration it only uses a simple HelloHandler but this example should be easily merged with other examples like those deploying servlets or webapps.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/examples/embedded-many-connectors.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_walkthrough"><a class="anchor" href="#_walkthrough"></a><a class="link" href="#_walkthrough">Walkthrough</a></h5>
<div class="paragraph">
<p>Start things up!
By using the <code>server.join()</code> the server thread will join with the current thread.
See <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()"><code>Thread.join()</code></a> for more details.</p>
</div>
</div>
<div class="sect4">
<h5 id="_maven-coordinates-3"><a class="anchor" href="#_maven-coordinates-3"></a><a class="link" href="#_maven-coordinates-3">Maven Coordinates</a></h5>
<div class="paragraph">
<p>To use this example in your project you will need the following Maven dependencies declared.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-server<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span>
<span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-security<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="embedded-secured-hello-handler"><a class="anchor" href="#embedded-secured-hello-handler"></a><a class="link" href="#embedded-secured-hello-handler">Secured Hello Handler</a></h4>
<div class="paragraph">
<p>This example shows how to wrap one handler with another one that handles security.
We have a simple Hello Handler that just return a greeting but add on the restriction that to get this greeting you must authenticate.
Another thing to remember is that this example uses the <code>ConstraintSecurityHandler</code> which is what supports the security mappings inside of the servlet api, it could be easier to show just the <code>SecurityHandler</code> usage, but the constraint provides more configuration power.
If you don&#8217;t need that you can drop the Constraint bits and use just the <code>SecurityHandler</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/examples/embedded-secured-hello-handler.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/SecuredHelloHandler.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_run-it-3"><a class="anchor" href="#_run-it-3"></a><a class="link" href="#_run-it-3">Run it!</a></h5>
<div class="paragraph">
<p>After you have started things up you should be able to navigate to <a href="http://localhost:8080/index.html" class="bare">http://localhost:8080/index.html</a> (assuming one is in the resource base directory) and you are good to go.</p>
</div>
</div>
<div class="sect4">
<h5 id="_the-realm-properties-file"><a class="anchor" href="#_the-realm-properties-file"></a><a class="link" href="#_the-realm-properties-file">The Realm Properties File</a></h5>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="properties">Unresolved directive in embedding/examples/embedded-secured-hello-handler.adoc - include::/home/joakim/code/jetty/jetty.project-10.0.x/documentation/jetty-documentation/../examples/embedded/src/test/resources/realm.properties[]</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_maven-coordinates-4"><a class="anchor" href="#_maven-coordinates-4"></a><a class="link" href="#_maven-coordinates-4">Maven Coordinates</a></h5>
<div class="paragraph">
<p>To use this example in your project you will need the following Maven dependencies declared.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-server<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="embedded-minimal-servlet"><a class="anchor" href="#embedded-minimal-servlet"></a><a class="link" href="#embedded-minimal-servlet">Minimal Servlet</a></h4>
<div class="paragraph">
<p>This example shows the bare minimum required for deploying a servlet into Jetty.
Note that this is strictly a servlet, not a servlet in the context of a web application, that example comes later.
This is purely just a servlet deployed and mounted on a context and able to process requests.
This example is excellent for situations where you have a simple servlet that you need to unit test, just mount it on a context and issue requests using your favorite http client library (like our Jetty client found in <a href="#client-http">[client-http]</a>).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/examples/embedded-minimal-servlet.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/MinimalServlets.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_walkthrough-2"><a class="anchor" href="#_walkthrough-2"></a><a class="link" href="#_walkthrough-2">Walkthrough</a></h5>
<div class="paragraph">
<p>Start things up! By using the <code>server.join()</code> the server thread will join with the current thread.
See <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()"><code>Thread.join()</code></a> for more details.</p>
</div>
<div class="paragraph">
<p>It is really simple to create useful servlets for testing behaviors. Sometimes you need a http server to run a unit test against that will return test content and wiring up a servlet like this makes it trivial.</p>
</div>
<div class="paragraph">
<p>After you have started things up you should be able to navigate to <a href="http://localhost:8080/" class="bare">http://localhost:8080/</a> and you are good to go.</p>
</div>
</div>
<div class="sect4">
<h5 id="_maven-coordinates-5"><a class="anchor" href="#_maven-coordinates-5"></a><a class="link" href="#_maven-coordinates-5">Maven Coordinates</a></h5>
<div class="paragraph">
<p>To use this example in your project you will need the following Maven dependencies declared.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-servlet<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="embedded-one-webapp"><a class="anchor" href="#embedded-one-webapp"></a><a class="link" href="#embedded-one-webapp">Web Application</a></h4>
<div class="paragraph">
<p>This example shows how to deploy a simple webapp with an embedded instance of Jetty.
This is useful when you want to manage the lifecycle of a server programmatically, either within a production application or as a simple way to deploying and debugging a full scale application deployment.
In many ways it is easier then traditional deployment since you control the classpath yourself, making this easy to wire up in a test case in Maven and issue requests using your favorite http client library (like our Jetty client found in <a href="#client-http">[client-http]</a>).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/examples/embedded-one-webapp.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_run-it-4"><a class="anchor" href="#_run-it-4"></a><a class="link" href="#_run-it-4">Run it!</a></h5>
<div class="paragraph">
<p>After you have started things up you should be able to navigate to <a href="http://localhost:8080/" class="bare">http://localhost:8080/</a> and you are good to go.</p>
</div>
</div>
<div class="sect4">
<h5 id="_maven-coordinates-6"><a class="anchor" href="#_maven-coordinates-6"></a><a class="link" href="#_maven-coordinates-6">Maven Coordinates</a></h5>
<div class="paragraph">
<p>To use this example in your project you will need the following Maven dependencies declared.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-webapp<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="embedded-webapp-jsp"><a class="anchor" href="#embedded-webapp-jsp"></a><a class="link" href="#embedded-webapp-jsp">Web Application with JSP</a></h4>
<div class="paragraph">
<p>This example is very similar to the one in the previous section, although it enables the embedded webapp to use JSPs.
As of jetty-9.2, we use the JSP engine from Apache, which relies on a Servlet Specification 3.1 style <code>ServletContainerInitializer</code> to initialize itself.
To get this to work with Jetty, you need to enable annotations processing, as shown in this example code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in embedding/embedded-examples.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneWebAppWithJsp.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_run-it-5"><a class="anchor" href="#_run-it-5"></a><a class="link" href="#_run-it-5">Run it!</a></h5>
<div class="paragraph">
<p>After you have started things up you should be able to navigate to <a href="http://localhost:8080/jsp/" class="bare">http://localhost:8080/jsp/</a> and click on any of the links to jsps.</p>
</div>
</div>
<div class="sect4">
<h5 id="_maven-coordinates-7"><a class="anchor" href="#_maven-coordinates-7"></a><a class="link" href="#_maven-coordinates-7">Maven Coordinates</a></h5>
<div class="paragraph">
<p>To use this example in your project, you will need the following Maven dependencies declared, in addition to those from the previous section:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-annotations<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span>
<span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>apache-jsp<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span>
<span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>apache-jstl<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="adding-embedded-examples"><a class="anchor" href="#adding-embedded-examples"></a><a class="link" href="#adding-embedded-examples">Adding Examples</a></h4>
<div class="paragraph">
<p>If you would like to add an example to this list, fork the documentation project from github (see the blue bar at the bottom of this page) and add the new page.
Feel free to add the example contents directly as a <code>[source.java]</code> and we will take it from there.</p>
</div>
<div class="paragraph">
<p>If you feel and example is missing, feel free to open a bug to ask for it.
No guarantees, but the more helpful and demonstrative it is the better.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="advanced-extras"><a class="anchor" href="#advanced-extras"></a><a class="link" href="#advanced-extras">Provided Servlets, Filters, and Handlers</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>Jetty ships with a bundle of servlets that interact with the key classes.
Most are in the org.eclipse.jetty.servlets package.
These servlets and filters are among the principle elements of Jetty as a component-based infrastructure that holds and runs J2EE applications.
As described, they play a major role in running and maintaining the Jetty server.</p>
</div>
<div class="paragraph">
<p>Also included are a number of Jetty specific handlers that allow access to internals of jetty that would not normally be exposed and are very useful testing environments and many production scenarios.</p>
</div>
<div class="sect2">
<h3 id="default-servlet"><a class="anchor" href="#default-servlet"></a><a class="link" href="#default-servlet">Default Servlet</a></h3>
<div class="sect3">
<h4 id="default-servlet-metadata"><a class="anchor" href="#default-servlet-metadata"></a><a class="link" href="#default-servlet-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.servlet.DefaultServlet</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-servlet</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlet/DefaultServlet.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlet/DefaultServlet.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="default-servlet-usage"><a class="anchor" href="#default-servlet-usage"></a><a class="link" href="#default-servlet-usage">Usage</a></h4>
<div class="paragraph">
<p>The <code>DefaultServlet</code> implements the <code>ResourceFactory</code> interface and extends the <code>HttpServlet</code> abstract class.
It is usually mapped to "/" and provides handling for static content, <code>OPTION</code> and <code>TRACE</code> methods for the context.
The <code>MOVE</code> method is allowed if <code>PUT</code> and <code>DELETE</code> are allowed.
See the <code>DefaultServlet</code> <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlet/DefaultServlet.html">javadoc</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="default-servlet-init"><a class="anchor" href="#default-servlet-init"></a><a class="link" href="#default-servlet-init">Init Parameters</a></h4>
<div class="paragraph">
<p>Jetty supports the following <code>initParameters</code>:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">acceptRanges</dt>
<dd>
<p>If <code>true</code>, range requests and responses are supported.</p>
</dd>
<dt class="hdlist1">dirAllowed</dt>
<dd>
<p>If <code>true</code>, directory listings are returned if no welcome file is found.
Otherwise 403 Forbidden displays.</p>
</dd>
<dt class="hdlist1">redirectWelcome</dt>
<dd>
<p>If <code>true</code>, welcome files are redirected rather that forwarded.</p>
</dd>
<dt class="hdlist1">welcomeServlets</dt>
<dd>
<p>If <code>true</code>, attempt to dispatch to welcome files that are servlets, but only after no matching static
resources could be found. If <code>false</code>, then a welcome file must exist on disk. If <code>exact</code>, then exact
servlet matches are supported without an existing file. Default is <code>false</code>. This must be <code>false</code> if you want directory listings,
but have index.jsp in your welcome file list.</p>
</dd>
<dt class="hdlist1">precompressed</dt>
<dd>
<p>If set to a comma separated list of encoding types (that may be listed in a requests Accept-Encoding header) to file extension mappings to look for and serve.
For example: <code>br=.br,gzip=.gz,bzip2=.bz</code>.
If set to a boolean <code>true</code>, then a default set of compressed formats will be used, otherwise no precompressed formats supported.</p>
</dd>
<dt class="hdlist1">gzip</dt>
<dd>
<p>Deprecated. Use <code>precompressed</code> instead. If set to <code>true</code>, then static content is served as gzip content encoded if a matching resource is found ending with ".gz".</p>
</dd>
<dt class="hdlist1">resourceBase</dt>
<dd>
<p>Set to replace the context resource base.</p>
</dd>
<dt class="hdlist1">resourceCache</dt>
<dd>
<p>If set, this is a context attribute name, which the servlet will use to look for a shared ResourceCache instance.</p>
</dd>
<dt class="hdlist1">relativeResourceBase</dt>
<dd>
<p>Set with a pathname relative to the base of the servlet context root. Useful for only serving static content out of only specific subdirectories.</p>
</dd>
<dt class="hdlist1">cacheControl</dt>
<dd>
<p>If set, all static content will have this value set as the cache-control header.</p>
</dd>
<dt class="hdlist1">pathInfoOnly</dt>
<dd>
<p>If <code>true</code>, only the path info will be applied to the resourceBase</p>
</dd>
<dt class="hdlist1">stylesheet</dt>
<dd>
<p>Set with the location of an optional stylesheet that will be used to decorate the directory listing html.</p>
</dd>
<dt class="hdlist1">etags</dt>
<dd>
<p>If <code>true</code>, weak etags will be generated and handled.</p>
</dd>
<dt class="hdlist1">maxCacheSize</dt>
<dd>
<p>Maximum total size of the cache or 0 for no cache.</p>
</dd>
<dt class="hdlist1">maxCachedFileSize</dt>
<dd>
<p>Maximum size of a file to cache.</p>
</dd>
<dt class="hdlist1">maxCachedFiles</dt>
<dd>
<p>Maximum number of files to cache.</p>
</dd>
<dt class="hdlist1">useFileMappedBuffer</dt>
<dd>
<p>If set to <code>true</code>, mapped file buffer serves static content.
Setting this value to <code>false</code> means that a direct buffer is used instead of a mapped file buffer.
By default, this is set to <code>true</code>.</p>
</dd>
<dt class="hdlist1">otherGzipFileExtensions</dt>
<dd>
<p>A comma separated list of other file extensions that signify that a file is gzip compressed.
If you don&#8217;t explicitly set this, it defaults to <code>.svgz</code>.</p>
</dd>
<dt class="hdlist1">encodingHeaderCacheSize</dt>
<dd>
<p>Max entries in a cache of ACCEPT-ENCODING headers</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect2">
<h3 id="proxy-servlet"><a class="anchor" href="#proxy-servlet"></a><a class="link" href="#proxy-servlet">Proxy Servlet</a></h3>
<div class="sect3">
<h4 id="proxy-servlet-metadata"><a class="anchor" href="#proxy-servlet-metadata"></a><a class="link" href="#proxy-servlet-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.proxy.ProxyServlet</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-proxy</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/proxy/ProxyServlet.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/proxy/ProxyServlet.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="proxy-servlet-usage"><a class="anchor" href="#proxy-servlet-usage"></a><a class="link" href="#proxy-servlet-usage">Usage</a></h4>
<div class="paragraph">
<p>An asynchronous servlet that forwards requests to another server either as a standard web reverse proxy (as defined by RFC2616) or as a transparent reverse proxy.
Internally it uses the async jetty-client.</p>
</div>
<div class="paragraph">
<p>To facilitate JMX monitoring, the <code>HttpClient</code> instance is set as context attribute, prefixed with the servlet&#8217;s name and exposed by the mechanism provided by <code>ContextHandler.MANAGED_ATTRIBUTES</code>.</p>
</div>
</div>
<div class="sect3">
<h4 id="proxy-servlet-init"><a class="anchor" href="#proxy-servlet-init"></a><a class="link" href="#proxy-servlet-init">Init Parameters</a></h4>
<div class="paragraph">
<p>The following init parameters may be used to configure the servlet:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">hostHeader</dt>
<dd>
<p>forces the host header to a particular value</p>
</dd>
<dt class="hdlist1">viaHost</dt>
<dd>
<p>the name to use in the Via header: Via: http/1.1 &lt;viaHost&gt;</p>
</dd>
<dt class="hdlist1">whiteList</dt>
<dd>
<p>comma-separated list of allowed proxy hosts</p>
</dd>
<dt class="hdlist1">blackList</dt>
<dd>
<p>comma-separated list of forbidden proxy hosts</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>In addition, there are a number of init parameters that can be used to configure the <code>HttpClient</code> instance used internally for the proxy.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">maxThreads</dt>
<dd>
<p>Default Value: 256
The max number of threads of HttpClient&#8217;s Executor</p>
</dd>
<dt class="hdlist1">maxConnections</dt>
<dd>
<p>Default Value: 32768
The max number of connections per destination.
RFC 2616 suggests that 2 connections should be opened per each destination, but browsers commonly open 6 or more.
If this <code>HttpClient</code> is used for load testing, it is common to have only one destination (the server to load test), and it is recommended to set this value to a high value (at least as much as the threads present in the executor).</p>
</dd>
<dt class="hdlist1">idleTimeout</dt>
<dd>
<p>Default Value: 30000
The idle timeout in milliseconds that a connection can be idle, that is without traffic of bytes in either direction.</p>
</dd>
<dt class="hdlist1">timeout</dt>
<dd>
<p>Default Value: 60000
The total timeout in milliseconds for the request/response conversation.</p>
</dd>
<dt class="hdlist1">requestBufferSize</dt>
<dd>
<p>Default Value: 4096
The size of the request buffer the request is written into.</p>
</dd>
<dt class="hdlist1">responseBufferSize</dt>
<dd>
<p>Default Value: 4096
The size of the response buffer the response is written into.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect2">
<h3 id="balancer-servlet"><a class="anchor" href="#balancer-servlet"></a><a class="link" href="#balancer-servlet">Balancer Servlet</a></h3>
<div class="sect3">
<h4 id="balancer-servlet-metadata"><a class="anchor" href="#balancer-servlet-metadata"></a><a class="link" href="#balancer-servlet-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.proxy.BalancerServlet</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-proxy</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/proxy/BalancerServlet.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/proxy/BalancerServlet.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="balancer-servlet-usage"><a class="anchor" href="#balancer-servlet-usage"></a><a class="link" href="#balancer-servlet-usage">Usage</a></h4>
<div class="paragraph">
<p>The Balancer servlet allows for simple, sticky round robin load balancing leveraging the <code>ProxyServlet</code> that is distributed with Jetty.</p>
</div>
<div class="paragraph">
<p>In addition to the parameters for <code>ProxyServlet</code>, the following are available for the balancer servlet:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">stickySessions</dt>
<dd>
<p>True if sessions should be sticky for subsequent requests</p>
</dd>
<dt class="hdlist1">balancerMember.&lt;name&gt;.proxyTo</dt>
<dd>
<p>One of more of these are required and will be the locations that are used to proxy traffic to.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect2">
<h3 id="cgi-servlet"><a class="anchor" href="#cgi-servlet"></a><a class="link" href="#cgi-servlet">CGI Servlet</a></h3>
<div class="sect3">
<h4 id="cgi-servlet-metadata"><a class="anchor" href="#cgi-servlet-metadata"></a><a class="link" href="#cgi-servlet-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.servlets.CGI</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-servlets</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/CGI.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/CGI.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="cgi-servlet-usage"><a class="anchor" href="#cgi-servlet-usage"></a><a class="link" href="#cgi-servlet-usage">Usage</a></h4>
<div class="paragraph">
<p>The CGI servlet class extends the abstract HttpServlet class.
When the init parameter is called, the cgi bin directory is set with the <code>cgibinResourceBase</code>.
Otherwise, it defaults to the resource base of the context.</p>
</div>
<div class="paragraph">
<p>The cgi bin uses three parameters:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">commandPrefix</dt>
<dd>
<p>The init parameter obtained when there is a prefix set to all commands directed to the method exec.</p>
</dd>
<dt class="hdlist1">Path</dt>
<dd>
<p>An init parameter passed to the exec environment as a PATH.
This must be run unpacked somewhere in the filesystem.</p>
</dd>
<dt class="hdlist1">ENV_</dt>
<dd>
<p>An init parameter that points to an environment variable with the name stripped of the leading ENV_ and using the init parameter value.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect2">
<h3 id="qos-filter"><a class="anchor" href="#qos-filter"></a><a class="link" href="#qos-filter">Quality of Service Filter</a></h3>
<div class="sect3">
<h4 id="qos-filter-metadata"><a class="anchor" href="#qos-filter-metadata"></a><a class="link" href="#qos-filter-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.servlets.QoSFilter</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-servlets</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/QoSFilter.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/QoSFilter.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="qos-filter-usage"><a class="anchor" href="#qos-filter-usage"></a><a class="link" href="#qos-filter-usage">Usage</a></h4>
<div class="paragraph">
<p>Jetty supports Continuations, which allow non-blocking handling of HTTP requests, so that threads can be allocated in a managed way to provide application specific Quality of Service (QoS).
The <code>QoSFilter</code> is a utility servlet filter that implements some QoS features.</p>
</div>
</div>
<div class="sect3">
<h4 id="qos-understanding"><a class="anchor" href="#qos-understanding"></a><a class="link" href="#qos-understanding">Understanding the Problem</a></h4>
<div class="sect4">
<h5 id="_waiting-for-resources"><a class="anchor" href="#_waiting-for-resources"></a><a class="link" href="#_waiting-for-resources">Waiting for Resources</a></h5>
<div class="paragraph">
<p>Web applications frequently use JDBC Connection pools to limit the simultaneous load on the database.
This protects the database from peak loads, but makes the web application vulnerable to thread starvation.
Consider a thread pool with 20 connections, being used by a web application that that typically receives 200 requests per second and each request holds a JDBC connection for 50ms.
Such a pool can service on average 200*20*1000/50 = 400 requests per second.</p>
</div>
<div class="paragraph">
<p>However, if the request rate rises above 400 per second, or if the database slows down (due to a large query) or becomes momentarily unavailable, the thread pool can very quickly accumulate many waiting requests.
If, for example, the website is "slashdotted" or experiences some other temporary burst of traffic and the request rate rises from 400 to 500 requests per second, then 100 requests per second join those waiting for a JDBC connection.
Typically, a web server&#8217;s thread pool contains only a few hundred threads, so a burst or slow DB need only persist for a few seconds to consume the entire web server&#8217;s thread pool; this is called thread starvation.
The key issue with thread starvation is that it effects the entire web application, and potentially the entire web server.
Even if the requests using the database are only a small proportion of the total requests on the web server, all requests are blocked because all the available threads are waiting on the JDBC connection pool.
This represents non-graceful degradation under load and provides a very poor quality of service.</p>
</div>
</div>
<div class="sect4">
<h5 id="_prioritizing-resources"><a class="anchor" href="#_prioritizing-resources"></a><a class="link" href="#_prioritizing-resources">Prioritizing Resources</a></h5>
<div class="paragraph">
<p>Consider a web application that is under extreme load.
This load might be due to a popularity spike (slashdot), usage burst (Christmas or close of business), or even a denial of service attack.
During such periods of load, it is often desirable not to treat all requests as equals, and to give priority to high value customers or administrative users.</p>
</div>
<div class="paragraph">
<p>The typical behavior of a web server under extreme load is to use all its threads to service requests and to build up a backlog of unserviced requests.
If the backlog grows deep enough, then requests start to timeout and users experience failures as well as delays.</p>
</div>
<div class="paragraph">
<p>Ideally, the web application should be able to examine the requests in the backlog, and give priority to high value customers and administrative users.
But with the standard blocking servlet API, it is not possible to examine a request without allocating a thread to that request for the duration of its handling.
There is no way to delay the handling of low priority requests, so if the resources are to be reallocated, then the low priority requests must all be failed.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="qos-applying"><a class="anchor" href="#qos-applying"></a><a class="link" href="#qos-applying">Applying the QoSFilter</a></h4>
<div class="paragraph">
<p>The Quality of Service Filter (QoSFilter) uses Continuations to avoid thread starvation, prioritize requests and give graceful degradation under load, to provide a high quality of service.
When you apply the filter to specific URLs within a web application, it limits the number of active requests being handled for those URLs.
Any requests in excess of the limit are suspended. When a request completes handling the limited URL, one of the waiting requests resumes and can be handled.
You can assign priorities to each suspended request, so that high priority requests resume before lower priority requests.</p>
</div>
<div class="sect4">
<h5 id="_required-jars"><a class="anchor" href="#_required-jars"></a><a class="link" href="#_required-jars">Required JARs</a></h5>
<div class="paragraph">
<p>To use the QoS Filter, these JAR files must be available in <code>WEB-INF/lib</code>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>$JETTY_HOME/lib/jetty-util.jar</p>
</li>
<li>
<p>$JETTY_HOME/lib/jetty-servlets.jar – contains QoSFilter</p>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="_sample-configuration"><a class="anchor" href="#_sample-configuration"></a><a class="link" href="#_sample-configuration">Sample Configuration</a></h5>
<div class="paragraph">
<p>Place the configuration in a webapp&#8217;s <code>web.xml</code> or <code>jetty-web.xml</code>.
The default configuration processes ten requests at a time, servicing more important requests first and queuing up the rest.
This example processes fifty requests at a time:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;filter&gt;</span>
<span class="tag">&lt;filter-name&gt;</span>QoSFilter<span class="tag">&lt;/filter-name&gt;</span>
<span class="tag">&lt;filter-class&gt;</span>org.eclipse.jetty.servlets.QoSFilter<span class="tag">&lt;/filter-class&gt;</span>
<span class="tag">&lt;init-param&gt;</span>
<span class="tag">&lt;param-name&gt;</span>maxRequests<span class="tag">&lt;/param-name&gt;</span>
<span class="tag">&lt;param-value&gt;</span>50<span class="tag">&lt;/param-value&gt;</span>
<span class="tag">&lt;/init-param&gt;</span>
<span class="tag">&lt;/filter&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="qos-filter-init"><a class="anchor" href="#qos-filter-init"></a><a class="link" href="#qos-filter-init">Configuring QoS Filter Parameters</a></h5>
<div class="paragraph">
<p>A semaphore polices the <code>maxRequests</code> limit.
The filter waits a short time while attempting to acquire the semaphore.
The <code>waitMs</code> init parameter controls the wait, avoiding the expense of a suspend if the semaphore is shortly available.
If the semaphore cannot be obtained, Jetty suspends the request for the default suspend period of the container or the value set as the <code>suspendMs</code> init parameter.</p>
</div>
<div class="paragraph">
<p>The QoS filter uses the following init parameters:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">maxRequests</dt>
<dd>
<p>The maximum number of requests to be serviced at a time. The default is 10.</p>
</dd>
<dt class="hdlist1">maxPriority</dt>
<dd>
<p>The maximum valid priority that can be assigned to a request.
A request with a high priority value is more important than a request with a low priority value. The default is 10.</p>
</dd>
<dt class="hdlist1">waitMs</dt>
<dd>
<p>The length of time, in milliseconds, to wait while trying to accept a new request.
Used when the maxRequests limit is reached.
Default is 50 ms.</p>
</dd>
<dt class="hdlist1">suspendMs</dt>
<dd>
<p>Length of time, in milliseconds, that the request will be suspended if it is not accepted immediately.
If not set, the container&#8217;s default suspend period applies. Default is -1 ms.</p>
</dd>
<dt class="hdlist1">managedAttr</dt>
<dd>
<p>If set to true, then this servlet is set as a <code>ServletContext</code> attribute with the filter name as the attribute name.
This allows a context external mechanism (for example, JMX via <code>ContextHandler.MANAGED_ATTRIBUTES</code>) to manage the configuration of the filter.</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_mapping-to-urls"><a class="anchor" href="#_mapping-to-urls"></a><a class="link" href="#_mapping-to-urls">Mapping to URLs</a></h5>
<div class="paragraph">
<p>You can use the <code>&lt;filter-mapping&gt;</code> syntax to map the QoSFilter to a servlet, either by using the servlet name, or by using a URL pattern.
In this example, a URL pattern applies the QoSFilter to every request within the web application context:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;filter-mapping&gt;</span>
<span class="tag">&lt;filter-name&gt;</span>QoSFilter<span class="tag">&lt;/filter-name&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>/*<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;/filter-mapping&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_setting-the-request-priority"><a class="anchor" href="#_setting-the-request-priority"></a><a class="link" href="#_setting-the-request-priority">Setting the Request Priority</a></h5>
<div class="paragraph">
<p>Requests with higher values have a higher priority.
The default request priorities assigned by the QoSFilter are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>2&#8201;&#8212;&#8201;For any authenticated request</p>
</li>
<li>
<p>1&#8201;&#8212;&#8201;For any request with a non-new valid session</p>
</li>
<li>
<p>0&#8201;&#8212;&#8201;For all other requests</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>To customize the priority, subclass QoSFilter and then override the <code>getPriority(ServletRequest request)</code> method to return an appropriate priority for the request.
You can then use this subclass as your QoS filter.
Here&#8217;s an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">class</span> <span class="class">ParsePriorityQoSFilter</span> <span class="directive">extends</span> QoSFilter
{
<span class="directive">protected</span> <span class="type">int</span> getPriority(ServletRequest request)
{
<span class="predefined-type">String</span> p = ((HttpServletRequest)request).getParameter(<span class="string"><span class="delimiter">&quot;</span><span class="content">priority</span><span class="delimiter">&quot;</span></span>);
<span class="keyword">if</span> (p!=<span class="predefined-constant">null</span>)
<span class="keyword">return</span> <span class="predefined-type">Integer</span>.parseInt(p);
<span class="keyword">return</span> <span class="integer">0</span>;
}
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="dos-filter"><a class="anchor" href="#dos-filter"></a><a class="link" href="#dos-filter">Denial of Service Filter</a></h3>
<div class="sect3">
<h4 id="dos-filter-metadata"><a class="anchor" href="#dos-filter-metadata"></a><a class="link" href="#dos-filter-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.servlets.DoSFilter</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-servlets</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/DoSFilter.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/DoSFilter.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="dos-filter-usage"><a class="anchor" href="#dos-filter-usage"></a><a class="link" href="#dos-filter-usage">Usage</a></h4>
<div class="paragraph">
<p>The Denial of Service (DoS) filter limits exposure to request flooding, whether malicious, or as a result of a misconfigured client.
The DoS filter keeps track of the number of requests from a connection per second.
If the requests exceed the limit, Jetty rejects, delays, or throttles the request, and sends a warning message.
The filter works on the assumption that the attacker might be written in simple blocking style, so by suspending requests you are hopefully consuming the attacker&#8217;s resources.</p>
</div>
</div>
<div class="sect3">
<h4 id="dos-filter-using"><a class="anchor" href="#dos-filter-using"></a><a class="link" href="#dos-filter-using">Using the DoS Filter</a></h4>
<div class="paragraph">
<p>Jetty places throttled requests in a priority queue, giving priority first to authenticated users and users with an HttpSession, then to connections identified by their IP addresses.
Connections with no way to identify them have lowest priority.
To uniquely identify authenticated users, you should implement the The extractUserId(ServletRequest request) function.</p>
</div>
<div class="sect4">
<h5 id="_required-jars-2"><a class="anchor" href="#_required-jars-2"></a><a class="link" href="#_required-jars-2">Required JARs</a></h5>
<div class="paragraph">
<p>To use the DoS Filter, these JAR files must be available in WEB-INF/lib:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>$JETTY_HOME/lib/jetty-util.jar</p>
</li>
<li>
<p>$JETTY_HOME/lib/jetty-servlets.jar</p>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="_sample-configuration-2"><a class="anchor" href="#_sample-configuration-2"></a><a class="link" href="#_sample-configuration-2">Sample Configuration</a></h5>
<div class="paragraph">
<p>Place the configuration in a webapp&#8217;s <code>web.xml</code> or <code>jetty-web.xml</code>.
The default configuration allows 25 requests per connection at a time, servicing more important requests first, and queuing up the rest.
This example allow 30 requests at a time:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;filter&gt;</span>
<span class="tag">&lt;filter-name&gt;</span>DoSFilter<span class="tag">&lt;/filter-name&gt;</span>
<span class="tag">&lt;filter-class&gt;</span>org.eclipse.jetty.servlets.DoSFilter<span class="tag">&lt;/filter-class&gt;</span>
<span class="tag">&lt;init-param&gt;</span>
<span class="tag">&lt;param-name&gt;</span>maxRequestsPerSec<span class="tag">&lt;/param-name&gt;</span>
<span class="tag">&lt;param-value&gt;</span>30<span class="tag">&lt;/param-value&gt;</span>
<span class="tag">&lt;/init-param&gt;</span>
<span class="tag">&lt;/filter&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="dos-filter-init"><a class="anchor" href="#dos-filter-init"></a><a class="link" href="#dos-filter-init">Configuring DoS Filter Parameters</a></h5>
<div class="paragraph">
<p>The following <code>init</code> parameters control the behavior of the filter:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">maxRequestsPerSec</dt>
<dd>
<p>Maximum number of requests from a connection per second.
Requests in excess of this are first delayed, then throttled.
Default is 25.</p>
</dd>
<dt class="hdlist1">delayMs</dt>
<dd>
<p>Delay imposed on all requests over the rate limit, before they are considered at all:</p>
<div class="ulist">
<ul>
<li>
<p>100 (ms) = Default</p>
</li>
<li>
<p>-1 = Reject request</p>
</li>
<li>
<p>0 = No delay</p>
</li>
<li>
<p>any other value = Delay in ms</p>
</li>
</ul>
</div>
</dd>
<dt class="hdlist1">maxWaitMs</dt>
<dd>
<p>Length of time, in ms, to blocking wait for the throttle semaphore.
Default is 50 ms.</p>
</dd>
<dt class="hdlist1">throttledRequests</dt>
<dd>
<p>Number of requests over the rate limit able to be considered at once.
Default is 5.</p>
</dd>
<dt class="hdlist1">throttleMs</dt>
<dd>
<p>Length of time, in ms, to async wait for semaphore. Default is 30000L.</p>
</dd>
<dt class="hdlist1">maxRequestMs</dt>
<dd>
<p>Length of time, in ms, to allow the request to run. Default is 30000L.</p>
</dd>
<dt class="hdlist1">maxIdleTrackerMs</dt>
<dd>
<p>Length of time, in ms, to keep track of request rates for a connection, before deciding that the user has gone away, and discarding it.
Default is 30000L.</p>
</dd>
<dt class="hdlist1">insertHeaders</dt>
<dd>
<p>If true, insert the DoSFilter headers into the response.
Defaults to true.</p>
</dd>
<dt class="hdlist1">trackSessions</dt>
<dd>
<p>If true, usage rate is tracked by session if a session exists.
Defaults to true.</p>
</dd>
<dt class="hdlist1">remotePort</dt>
<dd>
<p>If true and session tracking is not used, then rate is tracked by IP and port (effectively connection).
Defaults to false.</p>
</dd>
<dt class="hdlist1">ipWhitelist</dt>
<dd>
<p>A comma-separated list of IP addresses that will not be rate limited.</p>
</dd>
<dt class="hdlist1">managedAttr</dt>
<dd>
<p>If set to true, then this servlet is set as a ServletContext attribute with the filter name as the attribute name.
This allows a context external mechanism (for example, JMX via <code>ContextHandler.MANAGED_ATTRIBUTES</code>) to manage the configuration of the filter.</p>
</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="header-filter"><a class="anchor" href="#header-filter"></a><a class="link" href="#header-filter">Header Filter</a></h3>
<div class="sect3">
<h4 id="header-filter-metadata"><a class="anchor" href="#header-filter-metadata"></a><a class="link" href="#header-filter-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.servlets.HeaderFilter</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-servlets</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/HeaderFilter.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/HeaderFilter.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="header-filter-usage"><a class="anchor" href="#header-filter-usage"></a><a class="link" href="#header-filter-usage">Usage</a></h4>
<div class="paragraph">
<p>The header filter sets or adds headers to each response based on an optionally included/excluded list of path specs, mime types, and/or HTTP methods.
This filter processes its configured headers before calling <code>doFilter</code> in the filter chain. Some of the headers configured in this filter may get overwritten by other filters and/or the servlet processing the request.</p>
</div>
<div class="sect4">
<h5 id="_required-jars-3"><a class="anchor" href="#_required-jars-3"></a><a class="link" href="#_required-jars-3">Required JARs</a></h5>
<div class="paragraph">
<p>To use the Header Filter, these JAR files must be available in WEB-INF/lib:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>$JETTY_HOME/lib/jetty-http.jar</p>
</li>
<li>
<p>$JETTY_HOME/lib/jetty-servlets.jar</p>
</li>
<li>
<p>$JETTY_HOME/lib/jetty-util.jar</p>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="_sample-configuration-3"><a class="anchor" href="#_sample-configuration-3"></a><a class="link" href="#_sample-configuration-3">Sample Configuration</a></h5>
<div class="paragraph">
<p>Place the configuration in a webapp&#8217;s <code>web.xml</code> or <code>jetty-web.xml</code>.
This filter will perform the following actions on each response:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Set the X-Frame-Options header to DENY.</p>
</li>
<li>
<p>Add a Cache-Control header containing no-cache, no-store, must-revalidate</p>
</li>
<li>
<p>Set the Expires header to approximately one year in the future.</p>
</li>
<li>
<p>Add a Date header with the current system time.</p>
</li>
</ul>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Each action must be separated by a comma.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;filter&gt;</span>
<span class="tag">&lt;filter-name&gt;</span>HeaderFilter<span class="tag">&lt;/filter-name&gt;</span>
<span class="tag">&lt;filter-class&gt;</span>org.eclipse.jetty.servlets.HeaderFilter<span class="tag">&lt;/filter-class&gt;</span>
<span class="tag">&lt;init-param&gt;</span>
<span class="tag">&lt;param-name&gt;</span>headerConfig<span class="tag">&lt;/param-name&gt;</span>
<span class="tag">&lt;param-value&gt;</span>
set X-Frame-Options: DENY,
&quot;add Cache-Control: no-cache, no-store, must-revalidate&quot;,
setDate Expires: 31540000000,
addDate Date: 0
<span class="tag">&lt;/param-value&gt;</span>
<span class="tag">&lt;/init-param&gt;</span>
<span class="tag">&lt;/filter&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="header-filter-init"><a class="anchor" href="#header-filter-init"></a><a class="link" href="#header-filter-init">Configuring Header Filter Parameters</a></h5>
<div class="paragraph">
<p>The following <code>init</code> parameters control the behavior of the filter:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">includedPaths</dt>
<dd>
<p>Optional. Comma separated values of included path specs.</p>
</dd>
<dt class="hdlist1">excludedPaths</dt>
<dd>
<p>Optional. Comma separated values of excluded path specs.</p>
</dd>
<dt class="hdlist1">includedMimeTypes</dt>
<dd>
<p>Optional. Comma separated values of included mime types. The mime type will be guessed from the extension at the end of the request URL if the content type has not been set on the response.</p>
</dd>
<dt class="hdlist1">excludedMimeTypes</dt>
<dd>
<p>Optional. Comma separated values of excluded mime types. The mime type will be guessed from the extension at the end of the request URL if the content type has not been set on the response.</p>
</dd>
<dt class="hdlist1">includedHttpMethods</dt>
<dd>
<p>Optional. Comma separated values of included http methods.</p>
</dd>
<dt class="hdlist1">excludedHttpMethods</dt>
<dd>
<p>Optional. Comma separated values of excluded http methods.</p>
</dd>
<dt class="hdlist1">headerConfig</dt>
<dd>
<p>Comma separated values of actions to perform on headers. The syntax for each action is <code>action headerName: headerValue</code>.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Supported header actions:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>set</code> - causes set <code>setHeader</code> to be called on the response</p>
</li>
<li>
<p><code>add</code> - causes set <code>addHeader</code> to be called on the response</p>
</li>
<li>
<p><code>setDate</code> - causes <code>setDateHeader</code> to be called on the response.</p>
</li>
<li>
<p><code>addDate</code> - causes <code>addDateHeader</code> to be called on the response.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>If <code>setDate</code> or <code>addDate</code> is used, <code>headerValue</code> should be the number of milliseconds to add to the current system time before writing the header value.</p>
</div>
<div class="paragraph">
<p>If a property is both included and excluded by the filter configuration, then it will be considered excluded.</p>
</div>
<div class="paragraph">
<p>Path spec rules:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>If the spec starts with <code>^</code>, the spec is assumed to be a regex based path spec and will match with normal Java regex rules.</p>
</li>
<li>
<p>If the spec starts with <code>/</code>, the spec is assumed to be a Servlet url-pattern rules path spec for either an exact match or prefix based match.</p>
</li>
<li>
<p>If the spec starts with <code>*.</code>, the spec is assumed to be a Servlet url-pattern rules path spec for a suffix based match.</p>
</li>
<li>
<p>All other syntaxes are unsupported.</p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="gzip-filter"><a class="anchor" href="#gzip-filter"></a><a class="link" href="#gzip-filter">Gzip Handler</a></h3>
<div class="sect3">
<h4 id="gzip-filter-metadata"><a class="anchor" href="#gzip-filter-metadata"></a><a class="link" href="#gzip-filter-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.server.handler.gzip.GzipHandler</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-servlets</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/gzip/GzipHandler.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/gzip/GzipHandler.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="gzip-filter-usage"><a class="anchor" href="#gzip-filter-usage"></a><a class="link" href="#gzip-filter-usage">Usage</a></h4>
<div class="paragraph">
<p>The Jetty <code>GzipHandler</code> is a compression handler that you can apply to any dynamic resource (servlet).
It fixes many of the bugs in commonly available compression filters: it works with asynchronous servlets; it handles all ways to set content length.
Some user-agents might be excluded from compression to avoid common browser bugs (yes, this means IE!).</p>
</div>
<div class="paragraph">
<p>The <code>GzipHandler</code> can be added to the entire server by enabling the <code>gzip.mod</code> module.
It may also be added to individual contexts in a context xml file.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Jetty 9 only compresses using GZip.
Using deflate HTTP compression is not supported and will not function.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="gzip-filter-rules"><a class="anchor" href="#gzip-filter-rules"></a><a class="link" href="#gzip-filter-rules">Gzip Rules</a></h4>
<div class="paragraph">
<p><code>GzipHandler</code> will gzip the content of a response if:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>It is mapped to a matching path</p>
</li>
<li>
<p>The request method is configured to support gzip</p>
</li>
<li>
<p>The request is not from an excluded User-Agent</p>
</li>
<li>
<p>accept-encoding header is set to gzip</p>
</li>
<li>
<p>The response status code is &gt;=200 and &lt;300</p>
</li>
<li>
<p>The content length is unknown or more than the minGzipSize initParameter or the minGzipSize is 0(default)</p>
</li>
<li>
<p>The content-type does not match an excluded mime-type</p>
</li>
<li>
<p>No content-encoding is specified by the resource</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Compressing the content can greatly improve the network bandwidth usage, but at the cost of memory and CPU cycles.
The <a href="#default-servlet">DefaultServlet</a> is capable of serving pre-compressed static content, which saves memory and CPU.</p>
</div>
<div class="paragraph">
<p>The <code>GzipHandler</code> installs an output interceptor which passes through to the <code>DefaultServlet</code>.
If the content served by <code>DefaultServlet</code> is already compressed, the <code>GzipHandler</code> does nothing; if it is not compressed, the content is compressed on-the-fly.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Automatic precompression by the <code>DefaultServlet</code> can be configured.
Read more about the <code>DefaultServlet</code> <a href="#default-servlet">here.</a>
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="gzip-filter-init"><a class="anchor" href="#gzip-filter-init"></a><a class="link" href="#gzip-filter-init">Gzip Configuration</a></h4>
<div class="dlist">
<dl>
<dt class="hdlist1">minGzipSize</dt>
<dd>
<p>Content will only be compressed if content length is either unknown or greater than <code>minGzipSize</code>.</p>
</dd>
<dt class="hdlist1">checkGzExists (Deprecated)</dt>
<dd>
<p>False by default.
If set to true, the handler will check for pre-compressed content.</p>
</dd>
<dt class="hdlist1">includedMethods</dt>
<dd>
<p>List of HTTP methods to compress.
If not set, only <code>GET</code> requests are compressed.</p>
</dd>
<dt class="hdlist1">includedMimeTypes</dt>
<dd>
<p>List of MIME types to compress.</p>
</dd>
<dt class="hdlist1">excludedMimeTypes</dt>
<dd>
<p>List of MIME types not to compress.</p>
</dd>
<dt class="hdlist1">excludedAgentPatterns</dt>
<dd>
<p>A list of regex patterns for User-Agent names from which requests should not be compressed.</p>
</dd>
<dt class="hdlist1">excludedPaths</dt>
<dd>
<p>List of paths to exclude from compression.
Performs a <code>String.startsWith(String)</code> comparison to check if the path matches.
If it does match then there is no compression.
To match subpaths use excludePathPatterns instead.</p>
</dd>
<dt class="hdlist1">includedPaths</dt>
<dd>
<p>List of paths to consider for compression.</p>
</dd>
<dt class="hdlist1">includePaths</dt>
<dd>
<p>List of paths to definitely consider for compression.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect2">
<h3 id="cross-origin-filter"><a class="anchor" href="#cross-origin-filter"></a><a class="link" href="#cross-origin-filter">Cross Origin Filter</a></h3>
<div class="sect3">
<h4 id="cross-origin-filter-metadata"><a class="anchor" href="#cross-origin-filter-metadata"></a><a class="link" href="#cross-origin-filter-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.servlets.CrossOriginFilter</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-servlets</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/CrossOriginFilter.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/CrossOriginFilter.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="cross-origin-filter-usage"><a class="anchor" href="#cross-origin-filter-usage"></a><a class="link" href="#cross-origin-filter-usage">Usage</a></h4>
<div class="paragraph">
<p>HTTP requests made from a script are subject to well known restrictions, the most prominent being the same domain policy.</p>
</div>
<div class="paragraph">
<p>Firefox 3.5 introduced support for W3C&#8217;s Access Control for Cross-Site Requests specification, which requires a compliant client (for example, Firefox 3.5) and a compliant server (via this servlet filter).</p>
</div>
<div class="paragraph">
<p>This filter implements the required bits to support the server-side contract of the specification, and will allow a compliant client to perform cross-domain requests via the standard XMLHttpRequest object.
If the client does not issue a compliant cross-domain request, this filter does nothing, and its overhead is the check of the presence of the cross-domain HTTP header.</p>
</div>
<div class="paragraph">
<p>This is extremely useful in CometD web applications where it is now possible to perform cross-domain long polling without using script injection (also known as the JSONP transport), and therefore removing all the downsides that the JSONP transport has (it&#8217;s chattier, does not react quickly to failures, has a message size limit, uses GET instead of POST, etc.).</p>
</div>
</div>
<div class="sect3">
<h4 id="cross-origin-setup"><a class="anchor" href="#cross-origin-setup"></a><a class="link" href="#cross-origin-setup">Setup</a></h4>
<div class="paragraph">
<p>You will need to put the <code>jetty-servlets.jar</code> file onto your classpath.
If you are creating a webapp, ensure that this jar is included in your webapp&#8217;s <code>WEB-INF/lib</code>.
Or, if you are running Jetty embedded you will need to ensure that <code>jetty-servlets.jar</code> is on the execution classpath.
You can download the <code>jetty-servlets.jar</code> from the Maven Central Repository at <a href="https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-servlets/" class="bare">https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-servlets/</a>.
It is also available as part of the Jetty distribution in the <code>$JETTY_HOME/lib</code> directory.</p>
</div>
</div>
<div class="sect3">
<h4 id="cross-origin-config"><a class="anchor" href="#cross-origin-config"></a><a class="link" href="#cross-origin-config">Configuration</a></h4>
<div class="paragraph">
<p>This is a regular servlet filter that must be configured in <code>web.xml</code>.</p>
</div>
<div class="paragraph">
<p>It supports the following configuration parameters:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">allowedOrigins</dt>
<dd>
<p>A comma separated list of origins that are allowed to access the resources.
Default value is: * (all origins)</p>
</dd>
<dt class="hdlist1">allowedMethods</dt>
<dd>
<p>A comma separated list of HTTP methods that are allowed to be used when accessing the resources.
Default value is: GET,POST,HEAD</p>
</dd>
<dt class="hdlist1">allowedHeaders</dt>
<dd>
<p>A comma separated list of HTTP headers that are allowed to be specified when accessing the resources.
Default value is: X-Requested-With,Content-Type,Accept,Origin</p>
</dd>
<dt class="hdlist1">allowCredentials</dt>
<dd>
<p>A boolean indicating if the resource allows requests with credentials.
Default value is: true</p>
</dd>
<dt class="hdlist1">preflightMaxAge</dt>
<dd>
<p>The number of seconds that preflight requests can be cached by the client.
Default value is 1800 seconds (30 minutes)</p>
</dd>
<dt class="hdlist1">chainPreflight</dt>
<dd>
<p>If true preflight requests are chained to their target resource for normal handling (as an OPTION request).
Otherwise the filter will response to the preflight.
Default is true.</p>
</dd>
<dt class="hdlist1">exposedHeaders</dt>
<dd>
<p>A comma separated list of HTTP headers that are allowed to be exposed on the client.
Default value is the empty list.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>A typical configuration could be:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;web-app&gt;</span>
<span class="tag">&lt;filter&gt;</span>
<span class="tag">&lt;filter-name&gt;</span>cross-origin<span class="tag">&lt;/filter-name&gt;</span>
<span class="tag">&lt;filter-class&gt;</span>org.eclipse.jetty.servlets.CrossOriginFilter<span class="tag">&lt;/filter-class&gt;</span>
<span class="tag">&lt;/filter&gt;</span>
<span class="tag">&lt;filter-mapping&gt;</span>
<span class="tag">&lt;filter-name&gt;</span>cross-origin<span class="tag">&lt;/filter-name&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>/cometd/*<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;/filter-mapping&gt;</span>
<span class="tag">&lt;/web-app&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="resource-handler"><a class="anchor" href="#resource-handler"></a><a class="link" href="#resource-handler">Resource Handler</a></h3>
<div class="sect3">
<h4 id="resource-handler-metadata"><a class="anchor" href="#resource-handler-metadata"></a><a class="link" href="#resource-handler-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.server.handler.ResourceHandler</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-server</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ResourceHandler.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ResourceHandler.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="resource-handler-usage"><a class="anchor" href="#resource-handler-usage"></a><a class="link" href="#resource-handler-usage">Usage</a></h4>
<div class="paragraph">
<p>This handler will serve static content and handle If-Modified-Since headers and is suitable for simple serving of static content.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
There is no caching done with this handler, so if you are looking for a more fully featured way of serving static content look to the <a href="#default-servlet">Default Servlet</a>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Requests for resources that do not exist are let pass (Eg no 404&#8217;s).
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="_improving-the-look-and-feel"><a class="anchor" href="#_improving-the-look-and-feel"></a><a class="link" href="#_improving-the-look-and-feel">Improving the Look and Feel</a></h4>
<div class="paragraph">
<p>The resource handler has a default stylesheet which you can change by calling <code>setStyleSheet(String location)</code> with the location of a file on the system that it can locate through the resource loading system.
The default css is called <code>jetty-dir.css</code> and is located in the <code>jetty-util</code> package, pulled as a classpath resource from the <code>jetty-util</code> jar when requested through the <code>ResourceHandler</code>.</p>
</div>
</div>
<div class="sect3">
<h4 id="_embedded-example"><a class="anchor" href="#_embedded-example"></a><a class="link" href="#_embedded-example">Embedded Example</a></h4>
<div class="paragraph">
<p>The following is an example of a split fileserver, able to serve static content from multiple directory locations.
Since this handler does not return 404&#8217;s on content you are able to iteratively try multiple resource handlers to resolve content.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in extras/resource-handler.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/SplitFileServer.java<span class="type">[]</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="debug-handler"><a class="anchor" href="#debug-handler"></a><a class="link" href="#debug-handler">Debug Handler</a></h3>
<div class="sect3">
<h4 id="debug-handler-metadata"><a class="anchor" href="#debug-handler-metadata"></a><a class="link" href="#debug-handler-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.server.handler.DebugHandler</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-server</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/DebugHandler.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/DebugHandler.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="debug-handler-usage"><a class="anchor" href="#debug-handler-usage"></a><a class="link" href="#debug-handler-usage">Usage</a></h4>
<div class="paragraph">
<p>A simple handler that is useful to debug incoming traffic.
It will log entry and exit points of HTTP requests as well as the response code.</p>
</div>
</div>
<div class="sect3">
<h4 id="_usage-in-standard-distribution"><a class="anchor" href="#_usage-in-standard-distribution"></a><a class="link" href="#_usage-in-standard-distribution">Usage in Standard Distribution</a></h4>
<div class="paragraph">
<p>The debug handler can be added to Jetty by activating the <code>debug</code> module.</p>
</div>
</div>
<div class="sect3">
<h4 id="_embedded-usage"><a class="anchor" href="#_embedded-usage"></a><a class="link" href="#_embedded-usage">Embedded usage</a></h4>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Server server = <span class="keyword">new</span> Server(<span class="integer">8080</span>);
RolloverFileOutputStream outputStream = <span class="keyword">new</span> RolloverFileOutputStream(<span class="string"><span class="delimiter">&quot;</span><span class="content">MeinLogPfad/yyyy_mm_dd.request.log</span><span class="delimiter">&quot;</span></span>, <span class="predefined-constant">true</span>,<span class="integer">10</span>);
DebugHandler debugHandler = <span class="keyword">new</span> DebugHandler();
debugHandler.setOutputStream(outputStream);
debugHandler.setHandler(server.getHandler());
server.setHandler(debugHandler);
server.start();</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_example-output"><a class="anchor" href="#_example-output"></a><a class="link" href="#_example-output">Example output</a></h4>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="bash">15:14:05.838:qtp551889550-13-selector-0 OPENED HttpConnection@e910ee4{IDLE},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of 0}
15:14:05.846:qtp551889550-57:http://0:0:0:0:0:0:0:1:8080/ REQUEST 0:0:0:0:0:0:0:1 GET __utma=111872281.10102721.1321534299.1369833564.1370447492.35; __utmz=111872281.1321534299.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _opt_vi_RPY720HZ=75E12E63-0CD0-4D6F-8383-C90D5C8397C7; Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0
15:14:05.894:qtp551889550-57:http://0:0:0:0:0:0:0:1:8080/ RESPONSE 200 null
15:14:05.959:qtp551889550-59:http://0:0:0:0:0:0:0:1:8080/jetty.css REQUEST 0:0:0:0:0:0:0:1 GET __utma=111872281.10102721.1321534299.1369833564.1370447492.35; __utmz=111872281.1321534299.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _opt_vi_RPY720HZ=75E12E63-0CD0-4D6F-8383-C90D5C8397C7; visited=yes; Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0
15:14:05.962:qtp551889550-59:http://0:0:0:0:0:0:0:1:8080/jetty.css RESPONSE 200 null
15:14:06.052:qtp551889550-57:http://0:0:0:0:0:0:0:1:8080/images/jetty-header.jpg REQUEST 0:0:0:0:0:0:0:1 GET __utma=111872281.10102721.1321534299.1369833564.1370447492.35; __utmz=111872281.1321534299.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _opt_vi_RPY720HZ=75E12E63-0CD0-4D6F-8383-C90D5C8397C7; visited=yes; Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0
15:14:06.055:qtp551889550-57:http://0:0:0:0:0:0:0:1:8080/images/jetty-header.jpg RESPONSE 200 null
15:14:07.248:qtp551889550-59:http://0:0:0:0:0:0:0:1:8080/favicon.ico REQUEST 0:0:0:0:0:0:0:1 GET __utma=111872281.10102721.1321534299.1369833564.1370447492.35; __utmz=111872281.1321534299.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _opt_vi_RPY720HZ=75E12E63-0CD0-4D6F-8383-C90D5C8397C7; visited=yes; Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0
15:14:07.251:qtp551889550-59:http://0:0:0:0:0:0:0:1:8080/favicon.ico RESPONSE 404 text/html;charset=ISO-8859-1
15:14:09.330:qtp551889550-57 CLOSED HttpConnection@e910ee4{INTERESTED},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of -1}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="statistics-handler"><a class="anchor" href="#statistics-handler"></a><a class="link" href="#statistics-handler">Statistics Handler</a></h3>
<div class="sect3">
<h4 id="statistics-handler-metadata"><a class="anchor" href="#statistics-handler-metadata"></a><a class="link" href="#statistics-handler-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.server.handler.StatisticsHandler</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-server</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/StatisticsHandler.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/StatisticsHandler.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="statistics-handler-usage"><a class="anchor" href="#statistics-handler-usage"></a><a class="link" href="#statistics-handler-usage">Usage</a></h4>
<div class="paragraph">
<p>Jetty currently has two main statistics collection mechanisms:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Instances of <code>ConnectionStatistics</code> can collect statistics for each connection of a connector.</p>
</li>
<li>
<p>The <code>StatisticsHandler</code> class may be used to collect statistics for HTTP requests.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The <code>StatisticsHandler</code> and <code>ConnectionStatistics</code> are not included in the default Jetty configuration, these need to be configured manually or enabled using the Jetty <code>stats</code> module on the command line.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ java -jar {$jetty.home}/start.jar --add-to-start=stats</code></pre>
</div>
</div>
<div class="paragraph">
<p>In addition to these, the <code>SessionHandler</code> and <code>DefaultSessionCache</code> classes collect statistics for sessions.
These statistics are enabled by default and are accessible via JMX interface.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
To view statistics, you have to be able to connect to Jetty using either JConsole or some other JMX agent. See <a href="#using-jmx">[using-jmx]</a> for more information.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="request-statistics"><a class="anchor" href="#request-statistics"></a><a class="link" href="#request-statistics">Request Statistics</a></h4>
<div class="paragraph">
<p>To collect request statistics a <code>StatisticsHandler</code> must be configured as one of the handlers of the server.
Typically this can be done as the top level handler, but you may choose to configure a statistics handler for just one context by creating a context configuration file.
You can enable the <code>StatisticsHandler</code> by activating the <code>stats</code> modules on the command line.</p>
</div>
<div class="paragraph">
<p>Alternately, if you are making multiple changes to the Jetty configuration, you could include statistics handler configuration into your own Jetty xml configuration.
The following fragment shows how to configure a top level statistics handler:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">insertHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">StatsHandler</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.handler.StatisticsHandler</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="connection-statistics"><a class="anchor" href="#connection-statistics"></a><a class="link" href="#connection-statistics">Connection Statistics</a></h4>
<div class="paragraph">
<p>Detailed statistics on connection duration and number of messages are only collated when a connection is closed.
The current and maximum number of connections are the only "live" statistics.</p>
</div>
<div class="paragraph">
<p>The following example shows how to turn on connection statistics in the Jetty XML format.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addBeanToAllConnectors</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.io.ConnectionStatistics</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>A special variant of <code>ConnectionStatistics</code> called <code>IncludeExcludeConnectionStatistics</code> allows you to refine which types of connection you want to collect statistics for.</p>
</div>
<div class="paragraph">
<p>The following example shows how this can be used to record statistics only for WebSocket connections.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addBeanToAllConnectors</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.io.IncludeExcludeConnectionStatistics</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">include</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">arg</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="session-statistics"><a class="anchor" href="#session-statistics"></a><a class="link" href="#session-statistics">Session Statistics</a></h4>
<div class="paragraph">
<p>Session handling is built into Jetty for any servlet or webapp context.
Detailed statistics on session duration are only collated when a session is closed.
The current, minimum, and maximum number of sessions are the only "live" statistics.
The session statistics are enabled by default and do not need to be configured.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="inetaccess-handler"><a class="anchor" href="#inetaccess-handler"></a><a class="link" href="#inetaccess-handler">InetAccess Handler</a></h3>
<div class="sect3">
<h4 id="inetaccess-handler-metadata"><a class="anchor" href="#inetaccess-handler-metadata"></a><a class="link" href="#inetaccess-handler-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.server.handler.InetAccessHandler</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-server</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/InetAccessHandler.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/InetAccessHandler.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="inetaccess-handler-usage"><a class="anchor" href="#inetaccess-handler-usage"></a><a class="link" href="#inetaccess-handler-usage">Usage</a></h4>
<div class="paragraph">
<p>Controls access to the wrapped handler using the real remote IP. Control is provided by and <code>IncludeExcludeSet</code> over a <code>InetAddressSet</code>.
This handler uses the real internet address of the connection, not one reported in the forwarded for headers, as this cannot be as easily forged.</p>
</div>
</div>
<div class="sect3">
<h4 id="_usage-in-standard-distribution-2"><a class="anchor" href="#_usage-in-standard-distribution-2"></a><a class="link" href="#_usage-in-standard-distribution-2">Usage in Standard Distribution</a></h4>
<div class="paragraph">
<p>The InetAccess handler can be added to Jetty by activating the <code>inetaccess</code> module.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="moved-context-handler"><a class="anchor" href="#moved-context-handler"></a><a class="link" href="#moved-context-handler">Moved Context Handler</a></h3>
<div class="sect3">
<h4 id="moved-context-handler-metadata"><a class="anchor" href="#moved-context-handler-metadata"></a><a class="link" href="#moved-context-handler-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.server.handler.MovedContextHandler</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-server</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/MovedContextHandler.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/MovedContextHandler.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="moved-context-handler-usage"><a class="anchor" href="#moved-context-handler-usage"></a><a class="link" href="#moved-context-handler-usage">Usage</a></h4>
<div class="paragraph">
<p>You can use the <code>MovedContextHandler</code> to relocate or redirect a context that has changed context path and/or virtual hosts.</p>
</div>
<div class="paragraph">
<p>You can configure it to <em>permanently</em> redirect the old URL to the new URL, in which case Jetty sends a Http Status code of 301 to the browser with the new URL.
Alternatively, you can make it non-permanent, in which case Jetty sends a 302 Http Status code along with the new URL.</p>
</div>
<div class="paragraph">
<p>In addition, as with any other context, you can configure a list of virtual hosts, meaning that this context responds only to requests to one of the listed host names.</p>
</div>
<div class="paragraph">
<p>Suppose you have a context deployed at <code>/foo</code>, but that now you want to deploy at the root context <code>/</code> instead.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>First you reconfigure and redeploy the context on Jetty.</p>
</li>
<li>
<p>Next you need a way to redirect all the browsers who have bookmarked <code>/foo</code> to the new path.
You create a new <a href="#configuring-contexts">context xml</a> file in <code>{$jetty/.base}/webapps</code> and configure the <code>MovedContextHandler</code> to do the redirection from <code>/foo</code> to <code>/</code>.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Below is an example.
This is a permanent redirection, which also preserves <code>pathinfo</code> and query strings on the redirect:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.handler.MovedContextHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/foo<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">newContextURL</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">permanent</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">discardPathInfo</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>false<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">discardQuery</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>false<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">virtualHosts</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Item&gt;</span>209.235.245.73<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>127.0.0.73<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>acme.org<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>www.acme.org<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>server.acme.org<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="shutdown-handler"><a class="anchor" href="#shutdown-handler"></a><a class="link" href="#shutdown-handler">Shutdown Handler</a></h3>
<div class="sect3">
<h4 id="shutdown-handler-metadata"><a class="anchor" href="#shutdown-handler-metadata"></a><a class="link" href="#shutdown-handler-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.server.handler.ShutdownHandler</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-server</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ShutdownHandler.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ShutdownHandler.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="shutdown-handler-usage"><a class="anchor" href="#shutdown-handler-usage"></a><a class="link" href="#shutdown-handler-usage">Usage</a></h4>
<div class="paragraph">
<p>A handler that shuts the server down on a valid request.
This is used to perform "soft" restarts from Java.
If <code>_exitJvm</code> is set to true a hard <code>System.exit()</code> call is being made.</p>
</div>
<div class="paragraph">
<p>This is an example of how you can setup this handler directly with the Server.
It can also be added as a part of handler chain or collection.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"> Server server = <span class="keyword">new</span> Server(<span class="integer">8080</span>);
HandlerList handlers = <span class="keyword">new</span> HandlerList();
handlers.setHandlers(<span class="keyword">new</span> <span class="predefined-type">Handler</span><span class="type">[]</span>
{ someOtherHandler, <span class="keyword">new</span> ShutdownHandler(server,<span class="string"><span class="delimiter">&quot;</span><span class="content">secret password</span><span class="delimiter">&quot;</span></span>) });
server.setHandler(handlers);
server.start();</code></pre>
</div>
</div>
<div class="paragraph">
<p>This is an example that you can use to call the shutdown handler from within java.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"> <span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> attemptShutdown(<span class="type">int</span> port, <span class="predefined-type">String</span> shutdownCookie) {
<span class="keyword">try</span> {
<span class="predefined-type">URL</span> url = <span class="keyword">new</span> <span class="predefined-type">URL</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">http://localhost:</span><span class="delimiter">&quot;</span></span> + port + <span class="string"><span class="delimiter">&quot;</span><span class="content">/shutdown?token=</span><span class="delimiter">&quot;</span></span> + shutdownCookie);
<span class="predefined-type">HttpURLConnection</span> connection = (<span class="predefined-type">HttpURLConnection</span>)url.openConnection();
connection.setRequestMethod(<span class="string"><span class="delimiter">&quot;</span><span class="content">POST</span><span class="delimiter">&quot;</span></span>);
connection.getResponseCode();
logger.info(<span class="string"><span class="delimiter">&quot;</span><span class="content">Shutting down </span><span class="delimiter">&quot;</span></span> + url + <span class="string"><span class="delimiter">&quot;</span><span class="content">: </span><span class="delimiter">&quot;</span></span> + connection.getResponseMessage());
} <span class="keyword">catch</span> (<span class="exception">SocketException</span> e) {
logger.debug(<span class="string"><span class="delimiter">&quot;</span><span class="content">Not running</span><span class="delimiter">&quot;</span></span>);
<span class="comment">// Okay - the server is not running</span>
} <span class="keyword">catch</span> (<span class="exception">IOException</span> e) {
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="exception">RuntimeException</span>(e);
}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="default-handler"><a class="anchor" href="#default-handler"></a><a class="link" href="#default-handler">Default Handler</a></h3>
<div class="sect3">
<h4 id="default-handler-metadata"><a class="anchor" href="#default-handler-metadata"></a><a class="link" href="#default-handler-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.server.handler.DefaultHandler</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-server</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/DefaultHandler.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/DefaultHandler.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="default-handler-usage"><a class="anchor" href="#default-handler-usage"></a><a class="link" href="#default-handler-usage">Usage</a></h4>
<div class="paragraph">
<p>A simple handler that is useful to terminate handler chains with a clean fashion.
As in the example below, if a resource to be served is not matched within the resource handler the <code>DefaultHandler</code> will take care of producing a 404 page.
This class is a useful template to either extend and embrace or simply provide a similar implementation for customizing to your needs.
There is also an <a href="#error-handler">Error Handler</a> that services errors related to the servlet api specification, so it is best to not get the two confused.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The <code>DefaultHandler</code> will also handle serving out the <code>flav.ico</code> file should a request make it through all of the other handlers without being resolved.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"> Server server = <span class="keyword">new</span> Server(<span class="integer">8080</span>);
HandlerList handlers = <span class="keyword">new</span> HandlerList();
ResourceHandler resourceHandler = <span class="keyword">new</span> ResourceHandler();
resourceHandler.setBaseResource(Resource.newResource(<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span>));
handlers.setHandlers(<span class="keyword">new</span> <span class="predefined-type">Handler</span><span class="type">[]</span>
{ resourceHandler, <span class="keyword">new</span> DefaultHandler() });
server.setHandler(handlers);
server.start();</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="error-handler"><a class="anchor" href="#error-handler"></a><a class="link" href="#error-handler">Error Handler</a></h3>
<div class="sect3">
<h4 id="error-handler-metadata"><a class="anchor" href="#error-handler-metadata"></a><a class="link" href="#error-handler-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: <code>org.eclipse.jetty.server.handler.ErrorHandler</code></p>
</li>
<li>
<p>Maven Artifact: org.eclipse.jetty:jetty-server</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ErrorHandler.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ErrorHandler.html</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="error-handler-usage"><a class="anchor" href="#error-handler-usage"></a><a class="link" href="#error-handler-usage">Usage</a></h4>
<div class="paragraph">
<p>A handler that is used to report errors from servlet contexts and webapp contexts to report error conditions.
Primarily handles setting the various servlet spec specific response headers for error conditions.
Can be customized by extending; for more information on this see <a href="#custom-error-pages">Creating Custom Error Pages</a>.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="rewrite-handler"><a class="anchor" href="#rewrite-handler"></a><a class="link" href="#rewrite-handler">Rewrite Handler</a></h3>
<div class="paragraph">
<p>The <code>RewriteHandler</code> matches a request against a set of rules, and modifies the request accordingly for any rules that match.
The most common use is to rewrite request URIs, but it is capable of much more: rules can also be configured to redirect the response, set a cookie or response code on the response, modify the header, etc.</p>
</div>
<div class="sect3">
<h4 id="rewrite-handler-metadata"><a class="anchor" href="#rewrite-handler-metadata"></a><a class="link" href="#rewrite-handler-metadata">Info</a></h4>
<div class="ulist">
<ul>
<li>
<p>Classname: org.eclipse.jetty.rewrite.handler.RewriteHandler</p>
</li>
<li>
<p>Maven artifact: org.eclipse.jetty:jetty-rewrite</p>
</li>
<li>
<p>Javadoc: <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/RewriteHandler.html" class="bare">https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/RewriteHandler.html</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The standard Jetty distribution bundle contains the <code>jetty-rewrite</code> <a href="#startup-modules">module</a>, so all you need to do is to enable it using one of the <a href="#start-jar">module commands</a>, eg:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ java -jar start.jar --add-to-start=rewrite</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
If you are running the standard Jetty distribution with the sample test webapp, there will be a demo of the rewrite module at <a href="http://localhost:8080/test/rewrite/" class="bare">http://localhost:8080/test/rewrite/</a>
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="_usage"><a class="anchor" href="#_usage"></a><a class="link" href="#_usage">Usage</a></h4>
<div class="paragraph">
<p>The rewrite module enables the following Jetty xml config file on the execution path:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml">Unresolved directive in extras/rewrite-handler.adoc - include::/home/joakim/code/jetty/jetty.project-10.0.x/documentation/jetty-documentation/../jetty-rewrite/src/main/config/etc/jetty-rewrite.xml[]</code></pre>
</div>
</div>
<div class="paragraph">
<p>As the commented out code shows, you configure the <code>RewriteHandler</code> by adding various rules.</p>
</div>
<div class="paragraph">
<p>There is an example of <a href="#rewrite-rules">rules</a> configuration in the standard distribution in the <code>demo-base/etc/demo-rewrite-rules.xml</code> file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml">Unresolved directive in extras/rewrite-handler.adoc - include::/home/joakim/code/jetty/jetty.project-10.0.x/documentation/jetty-documentation/../demos/demo-jetty-webapp/src/main/config/modules/demo.d/demo-rewrite-rules.xml[]</code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_embedded-example-2"><a class="anchor" href="#_embedded-example-2"></a><a class="link" href="#_embedded-example-2">Embedded Example</a></h5>
<div class="paragraph">
<p>This is an example for embedded Jetty, which does something similar to the configuration file example above:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"> Server server = <span class="keyword">new</span> Server();
RewriteHandler rewrite = <span class="keyword">new</span> RewriteHandler();
rewrite.setRewriteRequestURI(<span class="predefined-constant">true</span>);
rewrite.setRewritePathInfo(<span class="predefined-constant">false</span>);
rewrite.originalPathAttribute(<span class="string"><span class="delimiter">&quot;</span><span class="content">requestedPath</span><span class="delimiter">&quot;</span></span>);
RedirectPatternRule redirect = <span class="keyword">new</span> RedirectPatternRule();
redirect.setPattern(<span class="string"><span class="delimiter">&quot;</span><span class="content">/redirect/*</span><span class="delimiter">&quot;</span></span>);
redirect.setReplacement(<span class="string"><span class="delimiter">&quot;</span><span class="content">/redirected</span><span class="delimiter">&quot;</span></span>);
rewrite.addRule(redirect);
RewritePatternRule oldToNew = <span class="keyword">new</span> RewritePatternRule();
oldToNew.setPattern(<span class="string"><span class="delimiter">&quot;</span><span class="content">/some/old/context</span><span class="delimiter">&quot;</span></span>);
oldToNew.setReplacement(<span class="string"><span class="delimiter">&quot;</span><span class="content">/some/new/context</span><span class="delimiter">&quot;</span></span>);
rewrite.addRule(oldToNew);
RewriteRegexRule reverse = <span class="keyword">new</span> RewriteRegexRule();
reverse.setRegex(<span class="string"><span class="delimiter">&quot;</span><span class="content">/reverse/([^/]*)/(.*)</span><span class="delimiter">&quot;</span></span>);
reverse.setReplacement(<span class="string"><span class="delimiter">&quot;</span><span class="content">/reverse/$2/$1</span><span class="delimiter">&quot;</span></span>);
rewrite.addRule(reverse);
server.setHandler(rewrite);</code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="rewrite-rules"><a class="anchor" href="#rewrite-rules"></a><a class="link" href="#rewrite-rules">Rules</a></h4>
<div class="paragraph">
<p>There are several types of rules that are written extending useful base rule classes.</p>
</div>
<div class="sect4">
<h5 id="_patternrule"><a class="anchor" href="#_patternrule"></a><a class="link" href="#_patternrule">PatternRule</a></h5>
<div class="paragraph">
<p>Matches against the request URI using the servlet pattern syntax.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/CookiePatternRule.html">CookiePatternRule</a></dt>
<dd>
<p>Adds a cookie to the response.</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/HeaderPatternRule.html">HeaderPatternRule</a></dt>
<dd>
<p>Adds/modifies a header in the response.</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/RedirectPatternRule.html">RedirectPatternRule</a></dt>
<dd>
<p>Redirects the response.</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/ResponsePatternRule.html">ResponsePatternRule</a></dt>
<dd>
<p>Sends the response code (status or error).</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/RewritePatternRule.html">RewritePatternRule</a></dt>
<dd>
<p>Rewrite the URI by replacing the matched request path with a fixed string.</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_regexrule"><a class="anchor" href="#_regexrule"></a><a class="link" href="#_regexrule">RegexRule</a></h5>
<div class="paragraph">
<p>Matches against the request URI using regular expressions.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/RedirectRegexRule.html">RedirectRegexRule</a></dt>
<dd>
<p>Redirect the response.</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/RewriteRegexRule.html">RewriteRegexRule</a></dt>
<dd>
<p>Rewrite the URI by matching with a regular expression.
(The replacement string may use <code>Template:$n</code> to replace the nth capture group.)</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_headerrule"><a class="anchor" href="#_headerrule"></a><a class="link" href="#_headerrule">HeaderRule</a></h5>
<div class="paragraph">
<p>Match against request headers. Match either on a header name and specific value, or on the presence of a header (with any value).</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/ForwardedSchemeHeaderRule.html">ForwardedSchemaHeaderRule</a></dt>
<dd>
<p>Set the scheme on the request (defaulting to HTTPS).</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_others"><a class="anchor" href="#_others"></a><a class="link" href="#_others">Others</a></h5>
<div class="paragraph">
<p>Extra rules that defy standard classification.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/MsieSslRule.html">MsieSslRule</a></dt>
<dd>
<p>Disables the keep alive for SSL from IE5 or IE6.</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/LegacyRule.html">LegacyRule</a></dt>
<dd>
<p>Implements the legacy API of RewriteHandler</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_rulecontainer"><a class="anchor" href="#_rulecontainer"></a><a class="link" href="#_rulecontainer">RuleContainer</a></h5>
<div class="paragraph">
<p>Groups rules together.
The contained rules will only be processed if the conditions for the <code>RuleContainer</code> evaluate to true.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/rewrite/handler/VirtualHostRuleContainer.html">VirtualHostRuleContainer</a></dt>
<dd>
<p>Groups rules that apply only to a specific virtual host or a set of virtual hosts</p>
</dd>
</dl>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="fastcgi"><a class="anchor" href="#fastcgi"></a><a class="link" href="#fastcgi">FastCGI Support</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="fastcgi-intro"><a class="anchor" href="#fastcgi-intro"></a><a class="link" href="#fastcgi-intro">FastCGI Introduction</a></h3>
<div class="paragraph">
<p>FastCGI is a network protocol primarily used by a <em>web server</em> to communicate to a <em>FastCGI server</em>.
FastCGI servers are typically used to serve web content generated by dynamic web languages, primarily <a href="http://www.php.net/">PHP</a>, but also Python, Ruby, Perl and others.</p>
</div>
<div class="paragraph">
<p>Web servers that supports FastCGI are, among others, <a href="http://httpd.apache.org/">Apache</a>, <a href="http://nginx.org/">Nginx</a>, and Jetty.
Web servers typically act as proxies, converting HTTP requests that they receive from clients (browsers) to FastCGI requests that are forwarded to the FastCGI server.
The FastCGI server spawns the dynamic web language interpreter, passing it the information contained in the FastCGI request and a dynamic web language script is executed, producing web content, typically HTML.
The web content is then formatted into a FastCGI response that is returned to the web server, which converts it to a HTTP response that is then returned to the client.</p>
</div>
<div class="paragraph">
<p>The most well known FastCGI server is the <a href="http://php-fpm.org/">PHP FastCGI Process Manager</a>, or <code>php-fpm</code>.
In the following we will assume that <code>php-fpm</code> is used as FastCGI server.</p>
</div>
<div class="paragraph">
<p>Jetty can be configured to act as a web server that supports FastCGI, replacing the functionality that is normally provided by Apache or Nginx.
This allows users to leverage Jetty features such as HTTP/2, the unique support that Jetty provides for HTTP/2 Push, Jetty&#8217;s scalability, and of course Jetty&#8217;s native support for Java Web Standards such as Servlets, JSPs, etc.</p>
</div>
<div class="paragraph">
<p>With such configuration, users can not only deploy their Java Web Applications in Jetty, but also serve their <a href="http://wordpress.com/">WordPress</a> site or blog or their <a href="https://drupal.org/">Drupal</a> site without having to install and manage multiple web servers.</p>
</div>
</div>
<div class="sect2">
<h3 id="configuring-fastcgi"><a class="anchor" href="#configuring-fastcgi"></a><a class="link" href="#configuring-fastcgi">Configuring Jetty for FastCGI</a></h3>
<div class="paragraph">
<p>In this section you will see how to configure Jetty to serve WordPress via FastCGI.</p>
</div>
<div class="paragraph">
<p>The first step is to have WordPress installed on your server machine, for example under <code>/var/www/wordpress</code>.
For more information about how to install WordPress, please refer to the <a href="https://codex.wordpress.org/Installing_WordPress">WordPress Installation Guide</a>.</p>
</div>
<div class="paragraph">
<p>The second step is to install <code>php-fpm</code> and make sure it is configured to listen on a TCP socket; typically it is configured to listen to <code>localhost:9000</code>.</p>
</div>
<div class="paragraph">
<p>The third step is to install Jetty, for example under <code>/opt/jetty</code>, called in the following <code>$JETTY_HOME</code>.
Refer to <a href="#jetty-downloading">Downloading Jetty</a> for more information about how to install Jetty.</p>
</div>
<div class="paragraph">
<p>The fourth step is to create a Jetty base directory (see <a href="#startup-base-and-home">[startup-base-and-home]</a>), called in the following <code>$JETTY_BASE</code>, where you setup the configuration needed to support FastCGI in Jetty, and configure the <code>fcgi</code>, <code>http</code> and <code>deploy</code> modules, so that Jetty will be able to accept HTTP requests from browsers, convert them in FastCGI, and proxy them to <code>php-fpm</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ mkdir -p /usr/jetty/wordpress
$ cd /usr/jetty/wordpress
$ java -jar $JETTY_HOME/start.jar --add-to-start=fcgi,http,deploy</code></pre>
</div>
</div>
<div class="paragraph">
<p>Therefore <code>$JETTY_BASE=/usr/jetty/wordpress</code>.</p>
</div>
<div class="paragraph">
<p>The fifth step is to deploy the web application that provides the proxying of client requests to the FastCGI server, <code>php-fpm</code>.
Typically this is done by deploying a <code>*.war</code> file in the <code>$JETTY_BASE/webapps</code> directory.
For FastCGI there is no web application that needs developed - all the work has already been done for you by Jetty.
As such you only need to deploy a Jetty context XML file that configures the web application directly.
Copy and paste the following content as <code>$JETTY_BASE/webapps/jetty-wordpress.xml</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.servlet.ServletContextHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">root</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.lang.String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>/var/www/wordpress<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">resourceBase</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">root</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">welcomeFiles</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">string</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Item&gt;</span>index.php<span class="tag">&lt;/Item&gt;</span><span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addFilter</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>/*<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">of</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.util.EnumSet</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Get</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">REQUEST</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">javax.servlet.DispatcherType</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setInitParameter</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>files<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>$path /index.php?p=$path<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addServlet</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.servlet.ServletHolder</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>default<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">forName</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.lang.Class</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>org.eclipse.jetty.servlet.DefaultServlet<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setInitParameter</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>dirAllowed<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>false<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>/<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addServlet</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>org.eclipse.jetty.fcgi.server.proxy.FastCGIProxyServlet<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>*.php<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setInitParameter</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>proxyTo<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>http://localhost:9000<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setInitParameter</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>prefix<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>/<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setInitParameter</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>scriptRoot<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">root</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setInitParameter</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>scriptPattern<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>(.+?\\.php)<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>An explanation of the above contents:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Linne 6 specifies the WordPress installation directory, in this example <code>/var/www/wordpress</code> (as defined in the first step).</p>
</li>
<li>
<p>Line 9 it is specified the context path at which WordPress will be served, in this example at the root context path <code>/</code>.</p>
</li>
<li>
<p>Line 10 specifies the resource base of the context, also set to the WordPress installation directory.
This allows Jetty to serve static resources directly from the WordPress installation directory.</p>
</li>
<li>
<p>Line 12 specifies the welcome file as <code>index.php</code>, so that Jetty can perform the proper redirects in case of URIs ending with the <code>/</code> character.</p>
</li>
<li>
<p>Line 15 specifies the <code>TryFilesFilter</code>, a Servlet Filter that has been inspired by the <a href="http://wiki.nginx.org/HttpCoreModule#try_files">try_files</a> functionality offered by Nginx.
This filter tries to serve the resource from the file system first, and if the resource is not found it forwards the request as <code>index.php?p=$path</code>, which will match the proxy servlet defined below.
Refer to the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/fcgi/server/proxy/TryFilesFilter.html">TryFilesFilter</a> documentation for further information.</p>
</li>
<li>
<p>Line 29specifies Jetty&#8217;s <code>DefaultServlet</code> to serve static content such as CSS files, JavaScript files, etc. <code>DefaultServlet</code> will serve these files by looking in the resource base of the context, defined at line 10 (see above).</p>
</li>
<li>
<p>Line 47 specifies the <code>FastCGIProxyServlet</code>, a Servlet that proxies HTTP requests arriving from clients to FastCGI requests to the FastCGI server.</p>
</li>
<li>
<p>Line 52 specifies the TCP address of the FastCGI server (<code>php-fpm</code>), where HTTP requests are forwarded as FastCGI requests.</p>
</li>
<li>
<p>Line 60 specifies once again the WordPress installation directory, so that the <code>FastCGIProxyServlet</code> can pass this information to the FastCGI server.</p>
</li>
<li>
<p>Line 64 specifies a regular expression that matches request URIs performed to this servlet, in addition to the standard URL mapping defined by Servlet at line 49.
Refer to the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.html">FastCGIProxyServlet</a> documentation for further information.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The last step is to start Jetty (see <a href="#startup">Starting Jetty</a>) and navigate to <code><a href="http://localhost:8080" class="bare">http://localhost:8080</a></code> with your browser and enjoy WordPress:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ cd $JETTY_BASE
$ java -jar /opt/jetty/start.jar</code></pre>
</div>
</div>
<div class="sect3">
<h4 id="configuring-fastcgi-http2"><a class="anchor" href="#configuring-fastcgi-http2"></a><a class="link" href="#configuring-fastcgi-http2">Configuring Jetty to Proxy HTTP/2 to FastCGI</a></h4>
<div class="paragraph">
<p>In order to configure Jetty to listen for HTTP/2 requests from clients that are HTTP/2 enabled and forward them to the FastCGI server as FastCGI requests, you need to enable the <code>http2</code> module, which in turn will require a TLS connector and consequently a keystore to read the key material required by TLS.</p>
</div>
<div class="paragraph">
<p>Enabling the <code>http2</code> is easy; in additions to the modules you have enabled above, add the <code>http2</code> module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ cd $JETTY_BASE
$ java -jar $JETTY_HOME/start.jar --add-to-start=http2</code></pre>
</div>
</div>
<div class="paragraph">
<p>The command above adds the <code>http2</code> module (and its dependencies) to the existing modules and uses the default Jetty keystore to provide the key material required by TLS.
You will want to use your own keystore with your own private key and certificate for your own domain.</p>
</div>
<div class="paragraph">
<p>Remember that by adding the <code>http2</code> module, you will start two JVMs: one that reads the configuration, and one that has the ALPN boot boot jar in the boot classpath, as explained in <a href="#http2-configuring">[http2-configuring]</a>.</p>
</div>
<div class="paragraph">
<p>Since now your site will run over TLS, you need to make sure that the WordPress URL is also configured so.
If you have followed the steps of the <a href="#configuring-fastcgi">previous section</a>, your WordPress site is served at <code><a href="http://localhost:8080" class="bare">http://localhost:8080</a></code>.
You will need to change that to be <code><a href="https://localhost:8443" class="bare">https://localhost:8443</a></code> from the WordPress administration web interface, or follow the <a href="http://codex.wordpress.org/Changing_The_Site_URL">WordPress instructions</a> to do so without using the administration web interface.</p>
</div>
<div class="paragraph">
<p>The minimal modules required to run WordPress with Jetty on HTTP/2 are therefore: <code>http2</code>, <code>http</code>, <code>fcgi</code> and <code>deploy</code>.
These will setup a clear text connector on port 8080 for HTTP/1.1 and a TLS connector on port 8443 for HTTP/2 and HTTP/1.1.</p>
</div>
<div class="paragraph">
<p>At this point, you can start Jetty (see <a href="#startup">Starting Jetty</a>), hit <code><a href="http://localhost:8080" class="bare">http://localhost:8080</a></code> with your browser and enjoy WordPress via HTTP/2 using a HTTP/2 enabled browser:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ cd $JETTY_BASE
$ java -jar $JETTY_HOME/start.jar</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you don&#8217;t have a HTTP/2 enabled browser, WordPress will still be available over HTTP/1.1.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="frameworks"><a class="anchor" href="#frameworks"></a><a class="link" href="#frameworks">Frameworks</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="framework-cdi"><a class="anchor" href="#framework-cdi"></a><a class="link" href="#framework-cdi">CDI</a></h3>
<div class="paragraph">
<p>Contexts and Dependency Injection for Java EE (<a href="http://www.cdi-spec.org/">CDI</a>) is a standard implemented by frameworks such as <a href="http://seamframework.org/Weld">Weld</a> and <a href="https://openwebbeans.apache.org/">Apache OpenWebBeans</a>.
This is a common way to assemble and configure webapplications by a process often referred to as 'decoration'.</p>
</div>
<div class="paragraph">
<p>Jetty integration of CDI frameworks allows CDI to be used to inject the Filters, Servlets and Listeners created within a Servlet Context.
There are two approaches to integration:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>CDI implementation can integrate with Jetty.
This requires the CDI implementation to have Jetty specific code.
Since Jetty-9.4.20 a loosely bound mechanism has been available for CDI implementations to extends the Jetty <code>DecoratedObjectFactory</code> without hard API dependencies.
Prior to that, CDI implementations directly called jetty APIs that need to be explicitly exposed to the webapp.</p>
</li>
<li>
<p>Alternately, Jetty can integrate with CDI implementations by using standard CDI SPIs.</p>
</li>
</ul>
</div>
<div class="sect3">
<h4 id="_jetty-cdi-modules"><a class="anchor" href="#_jetty-cdi-modules"></a><a class="link" href="#_jetty-cdi-modules">Jetty CDI Modules</a></h4>
<div class="paragraph">
<p>The Jetty distribution come with several CDI modules.
These modules do not provide CDI, but instead enable one of more integration mechanisms.</p>
</div>
<div class="sect4">
<h5 id="_jetty-cdi-module"><a class="anchor" href="#_jetty-cdi-module"></a><a class="link" href="#_jetty-cdi-module">Jetty <code>cdi</code> Module</a></h5>
<div class="paragraph">
<p>The <code>cdi</code> module supports either two modes of CDI integration which can be selected either by the "org.eclipse.jetty.cdi" context init parameter or the "org.eclipse.jetty.cdi" server attribute (which is initialised from the "jetty.cdi.mode" start property).
Supported modes are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>CdiSpiDecorator</code> Jetty will call the CDI SPI within the webapp to decorate objects (default).</p>
</li>
<li>
<p><code>CdiDecoratingLister</code> The webapp may register a decorator on the context attribute "org.eclipse.jetty.cdi.decorator".</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre>cd $JETTY_BASE
java -jar $JETTY_HOME/start.jar --add-to-start=cdi</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_jetty-cdi-decorate-module"><a class="anchor" href="#_jetty-cdi-decorate-module"></a><a class="link" href="#_jetty-cdi-decorate-module">Jetty <code>cdi-decorate</code> Module</a></h5>
<div class="paragraph">
<p>This module depends on the <code>cdi</code> module and sets the default mode to <code>CdiDecoratingListener</code>.
This is the preferred mode for Weld integration.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>cd $JETTY_BASE
java -jar $JETTY_HOME/start.jar --add-to-start=cdi-decorate</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_jetty-cdi-spi-module"><a class="anchor" href="#_jetty-cdi-spi-module"></a><a class="link" href="#_jetty-cdi-spi-module">Jetty <code>cdi-spi</code> Module</a></h5>
<div class="paragraph">
<p>This module depends on the <code>cdi</code> module and sets the default mode to <code>CdiSpiDecorator</code>.
This is the preferred mode for Open Web Beans integration.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>cd $JETTY_BASE
java -jar $JETTY_HOME/start.jar --add-to-start=cdi-spi</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_jetty-cdi2-module"><a class="anchor" href="#_jetty-cdi2-module"></a><a class="link" href="#_jetty-cdi2-module">Jetty <code>cdi2</code> Module</a></h5>
<div class="paragraph">
<p>This module supports the <strong>deprecated</strong> technique of exposing private Jetty decorate APIs to the CDI implementation in the webapp.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>cd $JETTY_BASE
java -jar $JETTY_HOME/start.jar --add-to-start=cdi2</pre>
</div>
</div>
<div class="paragraph">
<p>This module is equivalent to directly modifying the class path configuration with a <code>jetty-web.xml</code> like:</p>
</div>
<div class="listingblock XML">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;http://www.eclipse.org/jetty/configure.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">prependServerClass</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>-org.eclipse.jetty.util.Decorator<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">prependServerClass</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>-org.eclipse.jetty.util.DecoratedObjectFactory<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">prependServerClass</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>-org.eclipse.jetty.server.handler.ContextHandler.<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">prependServerClass</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>-org.eclipse.jetty.server.handler.ContextHandler<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">prependServerClass</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>-org.eclipse.jetty.servlet.ServletContextHandler<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
The <code>cdi2</code> module or directly modifying the web application classpath will not work for Jetty 10.0.0 and later.
It should only be used for versions prior to Jetty 9.4.20 and/or Weld 3.1.2.Final
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
</div>
<div class="sect3">
<h4 id="cdi-embedded"><a class="anchor" href="#cdi-embedded"></a><a class="link" href="#cdi-embedded">Embedded Jetty with CDI</a></h4>
<div class="paragraph">
<p>When starting embedded Jetty programmatically from the <code>main</code> method, to use CDI it may be
necessary:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>enable a Jetty CDI integration mode</p>
</li>
<li>
<p>and/or enable a CDI frame integration.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>However, depending on the exact configuration of the embedded server, either or both steps may not be required as `ServletContainerInitializer`s may be discovered.</p>
</div>
<div class="paragraph">
<p>The details for embedding CDI is explained in the <a href="#weld-embedded">Embedded Jetty with Weld</a> section, which can also be adapted to other CDI frameworks.
Unresolved directive in frameworks/chapter.adoc - include::weld.adoc[]</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="framework-jetty-osgi"><a class="anchor" href="#framework-jetty-osgi"></a><a class="link" href="#framework-jetty-osgi">OSGI</a></h3>
<div class="sect3">
<h4 id="_introduction"><a class="anchor" href="#_introduction"></a><a class="link" href="#_introduction">Introduction</a></h4>
<div class="paragraph">
<p>The Jetty OSGi infrastructure provides a Jetty container inside an OSGi container.
Traditional JavaEE webapps can be deployed, in addition to Jetty <code>ContextHandlers</code>, along with OSGi web bundles.
In addition, the infrastructure also supports the OSGi <code>HttpService</code> interface.</p>
</div>
</div>
<div class="sect3">
<h4 id="_general-setup"><a class="anchor" href="#_general-setup"></a><a class="link" href="#_general-setup">General Setup</a></h4>
<div class="paragraph">
<p>All of the Jetty jars contain manifest entries appropriate to ensure that they can be deployed into an OSGi container as bundles.
You will need to install some jetty jars into your OSGi container.
You can always find the Jetty jars either in the Maven Central repository, or you can <a href="https://www.eclipse.org/jetty/download.html">download</a> a distribution of Jetty.
Here&#8217;s the absolute minimal set of Jetty jars:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 7. Minimal Bundles</caption>
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Jar</th>
<th class="tableblock halign-left valign-top">Bundle Symbolic Name</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-util</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.util</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-http</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.http</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-io</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.io</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-security</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.security</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-server</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.server</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-servlet</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.servlet</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-webapp</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.webapp</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-deploy</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.deploy</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-xml</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.xml</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-servlet-api</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.servlet-api</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>You <strong>must also install the Apache Aries SPI Fly bundles</strong> as many parts of Jetty - for example ALPN, websocket, annotations - use the <code>ServiceLoader</code> mechanism, which requires an OSGi Service Loader Mediator like SPI Fly:</p>
</div>
<table id="spifly" class="tableblock frame-all grid-all stretch">
<caption class="title">Table 8. SPI Fly Bundles</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Jar</th>
<th class="tableblock halign-left valign-top">Bundle Symbolic Name</th>
<th class="tableblock halign-left valign-top">Location</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.apache.aries.spifly:org.apache.aries.spifly.dynamic.bundle-1.2.4.jar</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.apache.aries.spifly.dynamic.bundle</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://repo1.maven.org/maven2/org/apache/aries/spifly/org.apache.aries.spifly.dynamic.bundle/">Maven central</a></p></td>
</tr>
</tbody>
</table>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
We strongly recommend that you also deploy the <a href="#osgi-annotations">annotation-related</a> jars also, as the Servlet Specification increasingly relies on annotations for functionality.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>You will also need the <strong>OSGi Event Management service</strong> and the <strong>OSGi Configuration Management service</strong>.
If your OSGi container does not automatically make these available, you will need to add them in a way appropriate to your container.</p>
</div>
</div>
<div class="sect3">
<h4 id="_the-jetty-osgi-container"><a class="anchor" href="#_the-jetty-osgi-container"></a><a class="link" href="#_the-jetty-osgi-container">The Jetty OSGi Container</a></h4>
<div class="sect4">
<h5 id="_the-jetty-osgi-boot-jar"><a class="anchor" href="#_the-jetty-osgi-boot-jar"></a><a class="link" href="#_the-jetty-osgi-boot-jar">The jetty-osgi-boot jar</a></h5>
<div class="paragraph">
<p>Now that you have the basic set of Jetty jars installed, you can install the <a href="https://repo1.maven.org/maven2/org/eclipse/jetty/osgi/jetty-osgi-boot/">jetty-osgi-boot.jar</a> bundle, downloadable from the maven central repo <a href="https://repo1.maven.org/maven2/org/eclipse/jetty/osgi/jetty-osgi-boot/">here.</a></p>
</div>
<div class="paragraph">
<p>This bundle will instantiate and make available the Jetty OSGi container when it is started.
If this bundle is not auto-started upon installation into your OSGi container, you should start it manually using a command appropriate for your container.</p>
</div>
</div>
<div class="sect4">
<h5 id="customize-jetty-container"><a class="anchor" href="#customize-jetty-container"></a><a class="link" href="#customize-jetty-container">Customizing the Jetty Container</a></h5>
<div class="paragraph">
<p>Before going ahead with the install, you may want to customize the Jetty container.
In general this is done by a combination of System properties and the usual Jetty xml configuration files.
The way you define the System properties will depend on which OSGi container you are using, so ensure that you are familiar with how to set them for your environment.
In the following examples, we will assume that the OSGi container allows us to set System properties as simple <code>name=value</code> pairs.</p>
</div>
<div class="paragraph">
<p>The available System properties are:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.http.port</dt>
<dd>
<p>If not specified, this defaults to the usual jetty port of 8080.</p>
</dd>
<dt class="hdlist1">jetty.home</dt>
<dd>
<p>Either this property <em>or</em> the <strong>jetty.home.bundle</strong> <em>must</em> be specified.
This property should point to a file system location that has an <code>etc/</code> directory containing xml files to configure the Jetty container on startup.
For example:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">jetty.home=/opt/custom/jetty</code></pre>
</div>
</div>
<div class="paragraph">
<p>Where <code>/opt/custom/jetty</code> contains:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">etc/jetty.xml
etc/jetty-selector.xml
etc/jetty-deployer.xml
etc/jetty-special.xml</code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">jetty.home.bundle</dt>
<dd>
<p>Either this property <em>or</em> the <strong>jetty.home</strong> property must be specified.
This property should specify the symbolic name of a bundle which contains a directory called <code>jettyhome/</code>.
The <code>jettyhome/</code> directory should have a subdirectory called <code>etc/</code> that contains the xml files to be applied to Jetty on startup.
The jetty-osgi-boot.jar contains a <code>jettyhome/</code> directory with a default set of xml configuration files.
Here&#8217;s how you would specify it:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">jetty.home.bundle=org.eclipse.jetty.osgi.boot</code></pre>
</div>
</div>
<div class="paragraph">
<p>Here&#8217;s a partial listing of that jar that shows you the names of the xml files contained within it:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">META-INF/MANIFEST.MF
jettyhome/etc/jetty.xml
jettyhome/etc/jetty-deployer.xml
jettyhome/etc/jetty-http.xml</code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">jetty.etc.config.urls</dt>
<dd>
<p>This specifies the paths of the xml files that are to be used.
If not specified, they default to:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">etc/jetty.xml,etc/jetty-http.xml,etc/jetty-deployer.xml</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that the paths can either be relative or absolute, or a mixture.
If the path is relative, it is resolved against either <strong>jetty.home</strong> or <strong>jetty.home.bundle</strong>, whichever was specified.
You can use this ability to mix and match jetty configuration files to add functionality, such as adding in a https connector.
Here&#8217;s an example of adding a HTTPS connector, using the relevant files from the jetty-home:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>etc/jetty.xml, etc/jetty-http.xml, /opt/jetty/etc/jetty-ssl.xml, /opt/jetty/etc/jetty-https.xml, etc/jetty-deployer.xml</pre>
</div>
</div>
<div class="paragraph">
<p>Note that regardless of whether you set the <strong>jetty.home</strong> or <strong>jetty.home.bundle</strong> property, when Jetty executes the configuration files, it will set an appropriate value for <strong>jetty.home</strong> so that references in xml files to <code>&lt;property name="jetty.home"&gt;</code> will work.
Be careful, however, if you are mixing and matching relative and absolute configuration file paths: the value of <strong>jetty.home</strong> is determined from the resolved location of the <em>relative</em> files only.</p>
</div>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_the-jetty-container-as-an-osgi-service"><a class="anchor" href="#_the-jetty-container-as-an-osgi-service"></a><a class="link" href="#_the-jetty-container-as-an-osgi-service">The Jetty Container as an OSGi Service</a></h5>
<div class="paragraph">
<p>You can now go ahead and deploy the jetty-osgi-boot.jar into your OSGi container.
A Jetty server instance will be created, the xml config files applied to it, and then published as an OSGi service.
Normally, you will not need to interact with this service instance, however you can retrieve a reference to it using the usual OSGi API:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">org.osgi.framework.BundleContext bc;
org.osgi.framework.ServiceReference ref = bc.getServiceReference(<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span>);</code></pre>
</div>
</div>
<div class="paragraph">
<p>The Server service has a couple of properties associated with it that you can retrieve using the <code>org.osgi.framework.ServiceReference.getProperty(String)</code> method:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">managedServerName</dt>
<dd>
<p>The Jetty Server instance created by the jetty-osgi-boot.jar will be called "defaultJettyServer"</p>
</dd>
<dt class="hdlist1">jetty.etc.config.urls</dt>
<dd>
<p>The list of xml files resolved from either <strong>jetty.home</strong> or <strong>jetty.home.bundle</strong>/jettyhome</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_adding-more-jetty-servers"><a class="anchor" href="#_adding-more-jetty-servers"></a><a class="link" href="#_adding-more-jetty-servers">Adding More Jetty Servers</a></h5>
<div class="paragraph">
<p>As we have seen in the previous section, the jetty-osgi-boot code will create an <code>org.eclipse.jetty.server.Server</code> instance, apply the xml configuration files specified by <strong>jetty.etc.config.urls</strong> System property to it, and then register it as an OSGi Service.
The name associated with this default instance is <code>defaultJettyServer</code>.</p>
</div>
<div class="paragraph">
<p>You can create other Server instances, register them as OSGi Services, and the jetty-osgi-boot code will notice them, and configure them so that they can deploy <code>ContextHandlers</code> and webapp bundles.
When you deploy webapps or <code>ContextHandlers</code> as bundles or Services (see sections below) you can target them to be deployed to a particular server instance via
the Server&#8217;s name.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of how to create a new Server instance and register it with OSGi so that the jetty-osgi-boot code will find it and configure it so it can be a deployment target:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">class</span> <span class="class">Activator</span> <span class="directive">implements</span> BundleActivator
{
<span class="directive">public</span> <span class="type">void</span> start(BundleContext context) <span class="directive">throws</span> <span class="exception">Exception</span>
{
Server server = <span class="keyword">new</span> Server();
<span class="comment">//do any setup on Server in here</span>
<span class="predefined-type">String</span> serverName = <span class="string"><span class="delimiter">&quot;</span><span class="content">fooServer</span><span class="delimiter">&quot;</span></span>;
<span class="predefined-type">Dictionary</span> serverProps = <span class="keyword">new</span> <span class="predefined-type">Hashtable</span>();
<span class="comment">//define the unique name of the server instance</span>
serverProps.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">managedServerName</span><span class="delimiter">&quot;</span></span>, serverName);
serverProps.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.http.port</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">9999</span><span class="delimiter">&quot;</span></span>);
<span class="comment">//let Jetty apply some configuration files to the Server instance</span>
serverProps.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.etc.config.urls</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">file:/opt/jetty/etc/jetty.xml,file:/opt/jetty/etc/jetty-selector.xml,file:/opt/jetty/etc/jetty-deployer.xml</span><span class="delimiter">&quot;</span></span>);
<span class="comment">//register as an OSGi Service for Jetty to find</span>
context.registerService(Server.class.getName(), server, serverProps);
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now that we have created a new Server called "fooServer", we can deploy webapps and <code>ContextHandlers</code> as Bundles or Services to it (see below for more information on this). Here&#8217;s an example of deploying a webapp as a Service and targeting it to the "fooServer" Server we created above:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">class</span> <span class="class">Activator</span> <span class="directive">implements</span> BundleActivator
{
<span class="directive">public</span> <span class="type">void</span> start(BundleContext context) <span class="directive">throws</span> <span class="exception">Exception</span>
{
<span class="comment">//Create a webapp context as a Service and target it at the &quot;fooServer&quot; Server instance</span>
WebAppContext webapp = <span class="keyword">new</span> WebAppContext();
<span class="predefined-type">Dictionary</span> props = <span class="keyword">new</span> <span class="predefined-type">Hashtable</span>();
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span>);
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">/acme</span><span class="delimiter">&quot;</span></span>);
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">managedServerName</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">fooServer</span><span class="delimiter">&quot;</span></span>);
context.registerService(ContextHandler.class.getName(),webapp,props);
}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_deploying-bundles-as-webapps"><a class="anchor" href="#_deploying-bundles-as-webapps"></a><a class="link" href="#_deploying-bundles-as-webapps">Deploying Bundles as Webapps</a></h4>
<div class="paragraph">
<p>The Jetty OSGi container listens for the installation of bundles, and will automatically attempt to deploy any that appear to be webapps.</p>
</div>
<div class="paragraph">
<p>Any of the following criteria are sufficient for Jetty to deploy the bundle as a webapp:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Bundle contains a WEB-INF/web.xml file</dt>
<dd>
<p>If the bundle contains a web descriptor, then it is automatically deployed.
This is an easy way to deploy classic JavaEE webapps.</p>
</dd>
<dt class="hdlist1">Bundle MANIFEST contains Jetty-WarFolderPath (for releases prior tojetty-9.3) or Jetty-WarResourcePath</dt>
<dd>
<p>This is the location within the bundle of the webapp resources.
Typically this would be used if the bundle is not a pure webapp, but rather the webapp is a component of the bundle.
Here&#8217;s an example of a bundle where the resources of the webapp are not located at the root of the bundle, but rather inside the subdirectory <code>web/</code> :</p>
<div class="paragraph">
<p><code>MANIFEST</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Bundle-Name: Web
Jetty-WarResourcePath: web
Import-Package: javax.servlet;version=&quot;3.1&quot;,
javax.servlet.resources;version=&quot;3.1&quot;
Bundle-SymbolicName: com.acme.sample.web</code></pre>
</div>
</div>
<div class="paragraph">
<p>Bundle contents:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">META-INF/MANIFEST.MF
web/index.html
web/foo.html
web/WEB-INF/web.xml
com/acme/sample/web/MyStuff.class
com/acme/sample/web/MyOtherStuff.class</code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">Bundle MANIFEST contains Web-ContextPath</dt>
<dd>
<p>This header can be used in conjunction with either of the two preceding headers to control the context path to which the webapp is deployed, or alone to identify that the bundle&#8217;s contents should be published as a webapp.
This header is part of the RFC-66 specification for using webapps with OSGi.
Here&#8217;s an example based on the previous one where we use the <code>Web-ContextPath</code> header to set its deployment context path to be "/sample" :</p>
<div class="paragraph">
<p><code>MANIFEST</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Bundle-Name: Web
Jetty-WarResourcePath: web
Web-ContextPath: /sample
Import-Package: javax.servlet;version=&quot;3.1&quot;,
javax.servlet.resources;version=&quot;3.1&quot;
Bundle-SymbolicName: com.acme.sample.web</code></pre>
</div>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>You can also define extra headers in your bundle MANIFEST that help
customize the web app to be deployed:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Jetty-defaultWebXmlFilePath</dt>
<dd>
<p>The location of a <code>webdefault.xml</code> file to apply to the webapp.
The location can be either absolute (either absolute path or file: url), or relative (in which case it is interpreted as relative to the bundle root).
Defaults to the <code>webdefault.xml</code> file built into the Jetty OSGi container.</p>
</dd>
<dt class="hdlist1">Jetty-WebXmlFilePath</dt>
<dd>
<p>The location of the <code>web.xml</code> file.
The location can be either absolute (either absolute path or file: url), or relative (in which case it is interpreted as relative to the bundle root).
Defaults to <code>WEB-INF/web.xml</code></p>
</dd>
<dt class="hdlist1">Jetty-extraClassPath</dt>
<dd>
<p>A classpath of additional items to add to the webapp&#8217;s classloader.</p>
</dd>
<dt class="hdlist1">Jetty-bundleInstall</dt>
<dd>
<p>The path to the base folder that overrides the computed bundle installation - mostly useful for those OSGi frameworks that unpack bundles by default.</p>
</dd>
<dt class="hdlist1">Require-TldBundle</dt>
<dd>
<p>A comma separated list of bundle symbolic names of bundles containing TLDs that this webapp depends upon.</p>
</dd>
<dt class="hdlist1">managedServerName</dt>
<dd>
<p>The name of the Server instance to which to deploy this webapp bundle.
If not specified, defaults to the default Server instance called "defaultJettyServer".</p>
</dd>
<dt class="hdlist1">Jetty-WarFragmentResourcePath</dt>
<dd>
<p>The path within a fragment hosted by the web-bundle that contains static resources for the webapp.
The path is appended to the base resource for the webapp (see Jetty-WarResourcePath).</p>
</dd>
<dt class="hdlist1">Jetty-WarPrependFragmentResourcePath</dt>
<dd>
<p>The path within a fragment hosted by the web-bundle that contains static resources for the webapp.
The path is prepended to the base resource for the webapp (see Jetty-WarResourcePath).</p>
</dd>
<dt class="hdlist1">Jetty-ContextFilePath</dt>
<dd>
<p>A comma separated list of paths within the webapp bundle to Jetty context files that will be applied to the webapp.
Alternatively you may include a single Jetty context file called <code>jetty-webapp-context.xml</code> in the webapp bundle&#8217;s META-INF directory and it will be automatically applied to the webapp.</p>
</dd>
</dl>
</div>
<div class="sect4">
<h5 id="_determining-the-context-path-for-a-webapp-bundle"><a class="anchor" href="#_determining-the-context-path-for-a-webapp-bundle"></a><a class="link" href="#_determining-the-context-path-for-a-webapp-bundle">Determining the Context Path for a Webapp Bundle</a></h5>
<div class="paragraph">
<p>As we have seen in the previous section, if the bundle <code>MANIFEST</code> contains the RFC-66 header <strong>Web-ContextPath</strong>, Jetty will use that as the context path.
If the <code>MANIFEST</code> does not contain that header, then Jetty will concoct a context path based on the last element of the bundle&#8217;s location (by calling <code>Bundle.getLocation()</code>) after stripping off any file extensions.</p>
</div>
<div class="paragraph">
<p>For example, suppose we have a bundle whose location is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">file://some/where/over/the/rainbow/oz.war</code></pre>
</div>
</div>
<div class="paragraph">
<p>The corresponding synthesized context path would be:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">/oz</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_extra-properties-available-for-webapp-bundles"><a class="anchor" href="#_extra-properties-available-for-webapp-bundles"></a><a class="link" href="#_extra-properties-available-for-webapp-bundles">Extra Properties Available for Webapp Bundles</a></h5>
<div class="paragraph">
<p>You can further customize your webapp by including a Jetty context xml file that is applied to the webapp.
This xml file must be placed in <code>META-INF</code> of the bundle, and must be called <code>jetty-webapp-context.xml</code>.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of a webapp bundle listing containing such a file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">META-INF/MANIFEST.MF
META-INF/jetty-webapp-context.xml
web/index.html
web/foo.html
web/WEB-INF/web.xml
com/acme/sample/web/MyStuff.class
com/acme/sample/web/MyOtherStuff.class</code></pre>
</div>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of the contents of a <code>META-INF/jetty-webapp-context.xml</code> file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">defaultsDescriptor</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">bundle.root</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>META-INF/webdefault.xml<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>As you can see, it is a normal context xml file used to set up a webapp.
There are, however, some additional useful properties that can be referenced</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Server</dt>
<dd>
<p>This is a reference to the Jetty <code>org.eclipse.jetty.server.Server</code> instance to which the webapp being configured in the context xml file will be deployed.</p>
</dd>
<dt class="hdlist1">bundle.root</dt>
<dd>
<p>This is a reference to the <code>org.eclipse.jetty.util.resource.Resource</code> that represents the location of the Bundle.
Note that this could be either a directory in the file system if the OSGi container automatically unpacks bundles, or it may be a jar:file: url if the bundle remains packed.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_deploying-bundles-as-jetty-contexthandlers"><a class="anchor" href="#_deploying-bundles-as-jetty-contexthandlers"></a><a class="link" href="#_deploying-bundles-as-jetty-contexthandlers">Deploying Bundles as Jetty ContextHandlers</a></h4>
<div class="paragraph">
<p>In addition to deploying webapps, the Jetty OSGi container listens for the installation of bundles that are not heavyweight webapps, but rather use the flexible Jetty-specific concept of <code>ContextHandlers</code>.</p>
</div>
<div class="paragraph">
<p>The following is the criteria used to decide if a bundle can be deployed as a <code>ContextHandler</code>:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Bundle MANIFEST contains Jetty-ContextFilePath</dt>
<dd>
<p>A comma separated list of names of context files - each one of which represents a ContextHandler that should be deployed by Jetty.
The context files can be inside the bundle, external to the bundle somewhere on the file system, or external to the bundle in the <strong>jetty.home</strong> directory.</p>
<div class="paragraph">
<p>A context file that is inside the bundle:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Jetty-ContextFilePath: ./a/b/c/d/foo.xml</code></pre>
</div>
</div>
<div class="paragraph">
<p>A context file that is on the file system:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Jetty-ContextFilePath: /opt/app/contexts/foo.xml</code></pre>
</div>
</div>
<div class="paragraph">
<p>A context file that is relative to jetty.home:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Jetty-ContextFilePath: contexts/foo.xml</code></pre>
</div>
</div>
<div class="paragraph">
<p>A number of different context files:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Jetty-ContextFilePath: ./a/b/c/d/foo.xml,/opt/app/contexts/foo.xml,contexts/foo.xml</code></pre>
</div>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Other <code>MANIFEST</code> properties that can be used to configure the deployment of the <code>ContextHandler</code>:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">managedServerName</dt>
<dd>
<p>The name of the Server instance to which to deploy this webapp bundle.
If not specified, defaults to the default Server instance called "defaultJettyServer".</p>
</dd>
</dl>
</div>
<div class="sect4">
<h5 id="_determining-the-context-path-for-a-contexthandler-bundle"><a class="anchor" href="#_determining-the-context-path-for-a-contexthandler-bundle"></a><a class="link" href="#_determining-the-context-path-for-a-contexthandler-bundle">Determining the Context Path for a ContextHandler Bundle</a></h5>
<div class="paragraph">
<p>Usually, the context path for the ContextHandler will be set by the context xml file.
However, you can override any path set in the context xml file by using the <strong>Web-ContextPath</strong> header in the <code>MANIFEST</code>.</p>
</div>
</div>
<div class="sect4">
<h5 id="_extra-properties-available-for-context-xml-files"><a class="anchor" href="#_extra-properties-available-for-context-xml-files"></a><a class="link" href="#_extra-properties-available-for-context-xml-files">Extra Properties Available for Context Xml Files</a></h5>
<div class="paragraph">
<p>Before the Jetty OSGi container applies a context xml file found in a <strong>Jetty-ContextFilePath</strong> <code>MANIFEST</code> header, it sets a few useful propertiesthat can be referred to within the xml file:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Server</dt>
<dd>
<p>This is a reference to the Jetty <code>org.eclipse.jetty.server.Server</code> instance to which the <code>ContextHandler</code> being configured in the context xml file will be deployed.</p>
</dd>
<dt class="hdlist1">bundle.root</dt>
<dd>
<p>This is a reference to the <code>org.eclipse.jetty.util.resource.Resource</code> that represents the location of the Bundle (obtained by calling <code>Bundle.getLocation()</code>).
Note that this could be either a directory in the file system if the OSGi container automatically unpacks bundles, or it may be a jar:file: url if the bundle remains packed.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of a context xml file that makes use of these properties:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml">Unresolved directive in frameworks/osgi.adoc - include::/home/joakim/code/jetty/jetty.project-10.0.x/documentation/jetty-documentation/../jetty-osgi/test-jetty-osgi-context/src/main/context/acme.xml[]</code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="services-as-webapps"><a class="anchor" href="#services-as-webapps"></a><a class="link" href="#services-as-webapps">Deploying Services as Webapps</a></h4>
<div class="paragraph">
<p>In addition to listening for bundles whose format or <code>MANIFEST</code> entries define a webapp or <code>ContextHandler</code> for to be deployed, the Jetty OSGi container also listens for the registration of OSGi services that are instances of <code>org.eclipse.jetty.webapp.WebAppContext</code>.
So you may programmatically create a <code>WebAppContext</code>, register it as a service, and have Jetty pick it up and deploy it.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of doing that with a simple bundle that serves static content, and an <code>org.osgi.framework.BundleActivator</code> that instantiates the <code>WebAppContext</code>:</p>
</div>
<div class="paragraph">
<p>The bundle contents:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">META-INF/MANIFEST.MF
index.html
com/acme/osgi/Activator.class</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>MANIFEST.MF</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Bundle-Classpath: .
Bundle-Name: Jetty OSGi Test WebApp
DynamicImport-Package: org.eclipse.jetty.*;version=&quot;[9.0,10.0)&quot;
Bundle-Activator: com.acme.osgi.Activator
Import-Package: org.eclipse.jetty.server.handler;version=&quot;[9.0,10)&quot;,
org.eclipse.jetty.webapp;version=&quot;[9.0,10)&quot;,
org.osgi.framework;version= &quot;[1.5,2)&quot;,
org.osgi.service.cm;version=&quot;1.2.0&quot;,
org.osgi.service.packag eadmin;version=&quot;[1.2,2)&quot;,
org.osgi.service.startlevel;version=&quot;1.0.0&quot;,
org.osgi.service.url;version=&quot;1.0.0&quot;,
org.osgi.util.tracker;version= &quot;1.3.0&quot;,
org.xml.sax,org.xml.sax.helpers
Bundle-SymbolicName: com.acme.testwebapp</code></pre>
</div>
</div>
<div class="paragraph">
<p>The Activator code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">void</span> start(BundleContext context) <span class="directive">throws</span> <span class="exception">Exception</span>
{
WebAppContext webapp = <span class="keyword">new</span> WebAppContext();
<span class="predefined-type">Dictionary</span> props = <span class="keyword">new</span> <span class="predefined-type">Hashtable</span>();
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-WarResourcePath</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span>);
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">/acme</span><span class="delimiter">&quot;</span></span>);
context.registerService(WebAppContext.class.getName(),webapp,props);
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The above setup is sufficient for Jetty to recognize and deploy the <code>WebAppContext</code> at /acme.</p>
</div>
<div class="paragraph">
<p>As the example shows, you can use OSGi Service properties in order to communicate extra configuration information to Jetty:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Jetty-WarFolderPath (for releases prior to 9.3) or Jetty-WarResourcePath</dt>
<dd>
<p>The location within the bundle of the root of the static resources for the webapp</p>
</dd>
<dt class="hdlist1">Web-ContextPath</dt>
<dd>
<p>The context path at which to deploy the webapp.</p>
</dd>
<dt class="hdlist1">Jetty-defaultWebXmlFilePath</dt>
<dd>
<p>The location within the bundle of a <code>webdefault.xml</code> file to apply to the webapp.
Defaults to that of the Jetty OSGi container.</p>
</dd>
<dt class="hdlist1">Jetty-WebXmlFilePath</dt>
<dd>
<p>The location within the bundle of the <code>web.xml</code> file.
Defaults to <code>WEB-INF/web.xml</code></p>
</dd>
<dt class="hdlist1">Jetty-extraClassPath</dt>
<dd>
<p>A classpath of additional items to add to the webapp&#8217;s classloader.</p>
</dd>
<dt class="hdlist1">Jetty-bundleInstall</dt>
<dd>
<p>The path to the base folder that overrides the computed bundle installation - mostly useful for those OSGi frameworks that unpack bundles by default.</p>
</dd>
<dt class="hdlist1">Require-TldBundle</dt>
<dd>
<p>A comma separated list of bundle symbolic names of bundles containing TLDs that this webapp depends upon.</p>
</dd>
<dt class="hdlist1">managedServerName</dt>
<dd>
<p>The name of the Server instance to which to deploy this webapp.
If not specified, defaults to the default Server instance called "defaultJettyServer".</p>
</dd>
<dt class="hdlist1">Jetty-WarFragmentResourcePath</dt>
<dd>
<p>The path within a fragment hosted by the web-bundle that contains static resources for the webapp.
The path is appended to the base resource for the webapp (see Jetty-WarResourcePath).</p>
</dd>
<dt class="hdlist1">Jetty-WarPrependFragmentResourcePath</dt>
<dd>
<p>The path within a fragment hosted by the web-bundle that contains static resources for the webapp.
The path is prepended to the base resource for the webapp (see Jetty-WarResourcePath).</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="_deploying-services-as-contexthandlers"><a class="anchor" href="#_deploying-services-as-contexthandlers"></a><a class="link" href="#_deploying-services-as-contexthandlers">Deploying Services as ContextHandlers</a></h4>
<div class="paragraph">
<p>Similarly to WebApp`Contexts, the Jetty OSGi container can detect the registration of an OSGi Service that represents a <code>ContextHandler</code> and ensure that it is deployed.
The <code>ContextHandler</code> can either be fully configured before it is registered as an OSGi service - in which case the Jetty OSGi container will merely deploy it - or the <code>ContextHandler</code> can be partially configured, with the Jetty OSGi container completing the configuration via a context xml file and properties associated with the Service.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of doing that with a simple bundle that serves static content with an <code>org.osgi.framework.BundleActivator</code> that instantiates a <code>ContextHandler</code> and registers it as an OSGi Service, passing in properties that define a context xml file and context path for Jetty to apply upon deployment:</p>
</div>
<div class="paragraph">
<p>The bundle contents:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">META-INF/MANIFEST.MF
static/index.html
acme.xml
com/acme/osgi/Activator.class
com/acme/osgi/Activator$1.class</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>MANIFEST</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Bundle-Classpath: .
Bundle-Name: Jetty OSGi Test Context
DynamicImport-Package: org.eclipse.jetty.*;version=&quot;[9.0,10.0)&quot;
Bundle-Activator: com.acme.osgi.Activator
Import-Package: javax.servlet;version=&quot;2.6.0&quot;,
javax.servlet.resources;version=&quot;2.6.0&quot;,
org.eclipse.jetty.server.handler;version=&quot;[9.0,10)&quot;,
org.osgi.framework;version=&quot;[1.5,2)&quot;,
org.osgi.service.cm;version=&quot;1.2.0&quot;,
org.osgi.service.packageadmin;version=&quot;[1.2,2)&quot;,
org.osgi.service.startlevel;version=&quot;1.0.0.o&quot;,
org.osgi.service.url;version=&quot;1.0.0&quot;,
org.osgi.util.tracker;version=&quot;1.3.0&quot;,
org.xml.sax,org.xml.sax.helpers
Bundle-SymbolicName: com.acme.testcontext</code></pre>
</div>
</div>
<div class="paragraph">
<p>The Activator code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">void</span> start(<span class="directive">final</span> BundleContext context) <span class="directive">throws</span> <span class="exception">Exception</span>
{
ContextHandler ch = <span class="keyword">new</span> ContextHandler();
ch.addEventListener(<span class="keyword">new</span> ServletContextListener () {
<span class="annotation">@Override</span>
<span class="directive">public</span> <span class="type">void</span> contextInitialized(ServletContextEvent sce)
{
<span class="predefined-type">System</span>.err.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">Context is initialized</span><span class="delimiter">&quot;</span></span>);
}
<span class="annotation">@Override</span>
<span class="directive">public</span> <span class="type">void</span> contextDestroyed(ServletContextEvent sce)
{
<span class="predefined-type">System</span>.err.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">Context is destroyed!</span><span class="delimiter">&quot;</span></span>);
}
});
<span class="predefined-type">Dictionary</span> props = <span class="keyword">new</span> <span class="predefined-type">Hashtable</span>();
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">Web-ContextPath</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">/acme</span><span class="delimiter">&quot;</span></span>);
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">Jetty-ContextFilePath</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">acme.xml</span><span class="delimiter">&quot;</span></span>);
context.registerService(ContextHandler.class.getName(),ch,props);
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The contents of the <code>acme.xml</code> context file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml">Unresolved directive in frameworks/osgi.adoc - include::/home/joakim/code/jetty/jetty.project-10.0.x/documentation/jetty-documentation/../jetty-osgi/test-jetty-osgi-context/src/main/context/acme.xml[]</code></pre>
</div>
</div>
<div class="paragraph">
<p>You may also use the following OSGi Service properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">managedServerName</dt>
<dd>
<p>The name of the Server instance to which to deploy this webapp.
If not specified, defaults to the default Server instance called "defaultJettyServer".</p>
</dd>
</dl>
</div>
<div class="sect4">
<h5 id="_extra-properties-available-for-context-xml-files-2"><a class="anchor" href="#_extra-properties-available-for-context-xml-files-2"></a><a class="link" href="#_extra-properties-available-for-context-xml-files-2">Extra Properties Available for Context Xml Files</a></h5>
<div class="paragraph">
<p>Before the Jetty OSGi container applies a context xml file found in a <code>Jetty-ContextFilePath</code> property, it sets a few useful properties that can be referred to within the xml file:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Server</dt>
<dd>
<p>This is a reference to the Jetty <code>org.eclipse.jetty.server.Server</code> instance to which the <code>ContextHandler</code> being configured in the context xml file will be deployed.</p>
</dd>
<dt class="hdlist1">bundle.root</dt>
<dd>
<p>This is a reference to the <code>org.eclipse.jetty.util.resource.Resource</code> that represents the location of the Bundle publishing the <code>ContextHandler</code> as a Service (obtained by calling <code>Bundle.getLocation()</code>).
Note that this could be either a directory in the file system if the OSGi container automatically unpacks bundles, or it may be a jar:file: url if the bundle remains packed.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>In the example above, you can see both of these properties being used in the context xml file.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_support-for-the-osgi-service-platform-enterprise-specification"><a class="anchor" href="#_support-for-the-osgi-service-platform-enterprise-specification"></a><a class="link" href="#_support-for-the-osgi-service-platform-enterprise-specification">Support for the OSGi Service Platform Enterprise Specification</a></h4>
<div class="paragraph">
<p>The Jetty OSGi container implements several aspects of the Enterprise Specification v4.2 for the <code>WebAppContexts</code> and <code>ContextHandlers</code> that it deploys from either bundles or OSGi services as outlined in foregoing sections.</p>
</div>
<div class="sect4">
<h5 id="_context-attributes"><a class="anchor" href="#_context-attributes"></a><a class="link" href="#_context-attributes">Context Attributes</a></h5>
<div class="paragraph">
<p>For each <code>WebAppContext</code> or <code>ContextHandler</code>, the following context attribute is set, as required by section <em>128.6.1 Bundle Context</em> page 427:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">osgi-bundleContext</dt>
<dd>
<p>The value of this attribute is the <code>BundleContext</code> representing the Bundle associated with the <code>WebAppContext</code> or <code>ContextHandler</code>.</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_service-attributes"><a class="anchor" href="#_service-attributes"></a><a class="link" href="#_service-attributes">Service Attributes</a></h5>
<div class="paragraph">
<p>As required by the specification section <em>128.3.4 Publishing the Servlet Context</em> page 421, each <code>WebAppContext</code> and <code>ContextHandler</code> deployed by the Jetty OSGi container is also published as an OSGi service (unless it has been already - see sections 1.6 and 1.7).
The following properties are associated with these services:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">osgi.web.symbolicname</dt>
<dd>
<p>The symbolic name of the Bundle associated with the <code>WebAppContext</code> or <code>ContextHandler</code></p>
</dd>
<dt class="hdlist1">osgi.web.version</dt>
<dd>
<p>The Bundle-Version header from the Bundle associated with the <code>WebAppContext</code> or <code>ContextHandler</code></p>
</dd>
<dt class="hdlist1">osgi.web.contextpath</dt>
<dd>
<p>The context path of the <code>WebAppContext</code> or <code>ContextHandler</code></p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="_osgi-events"><a class="anchor" href="#_osgi-events"></a><a class="link" href="#_osgi-events">OSGi Events</a></h5>
<div class="paragraph">
<p>As required by the specification section <em>128.5 Events</em> pg 426, the
following OSGi Event Admin events will be posted:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">org/osgi/service/web/DEPLOYING</dt>
<dd>
<p>The Jetty OSGi container is about to deploy a <code>WebAppContext</code> or <code>ContextHandler</code></p>
</dd>
<dt class="hdlist1">org/osgi/service/web/DEPLOYED</dt>
<dd>
<p>The Jetty OSGi container has finished deploying a <code>WebAppContext</code> or <code>ContextHandler</code> and it is in service</p>
</dd>
<dt class="hdlist1">org/osgi/service/web/UNDEPLOYING</dt>
<dd>
<p>The Jetty OSGi container is about to undeploy a <code>WebAppContext</code> or <code>ContextHandler</code></p>
</dd>
<dt class="hdlist1">org/osgi/service/web/UNDEPLOYED</dt>
<dd>
<p>The Jetty OSGi container has finished undeploying a <code>WebAppContext</code> or <code>ContextHandler</code> and it is no longer in service</p>
</dd>
<dt class="hdlist1">org/osgi/service/web/FAILED</dt>
<dd>
<p>The Jetty OSGi container failed to deploy a <code>WebAppContext</code> or <code>ContextHandler</code></p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_using-jsps"><a class="anchor" href="#_using-jsps"></a><a class="link" href="#_using-jsps">Using JSPs</a></h4>
<div class="sect4">
<h5 id="_setup"><a class="anchor" href="#_setup"></a><a class="link" href="#_setup">Setup</a></h5>
<div class="paragraph">
<p>In order to use JSPs with your webapps and bundles you will need to install the JSP and JSTL jars and their dependencies into your OSGi container.
Some you will find in the Jetty distribution, whereas others you will need to download from <a href="https://repo1.maven.org/maven2/org/eclipse/jetty/orbit/">Maven central</a>.
Here is the list of recommended jars (NOTE the version numbers may change in future):</p>
</div>
<table id="osgi-jsp" class="tableblock frame-all grid-all stretch">
<caption class="title">Table 9. Jars Required for JSP</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Jar</th>
<th class="tableblock halign-left valign-top">Bundle Symbolic Name</th>
<th class="tableblock halign-left valign-top">Location</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">The <a href="#osgi-annotations">annotation jars</a></p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.mortbay.jasper:apache-el</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.mortbay.jasper.apache-el</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Distribution lib/apache-jsp</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.mortbay.jasper:apache-jsp</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.mortbay.jasper.apache-jsp</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Distribution lib/apache-jsp</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty:apache-jsp</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.apache-jsp</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Distribution lib/apache-jsp</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jdt.core-3.8.2.v20130121.jar</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jdt.core.compiler.batch</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Distribution lib/apache-jsp</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.osgi:jetty-osgi-boot-jsp</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.osgi.boot.jsp</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://repo1.maven.org/maven2/org/eclipse/jetty/osgi/jetty-osgi-boot-jsp">Maven central</a></p></td>
</tr>
</tbody>
</table>
<div class="quoteblock">
<blockquote>
<div class="olist NOTE">
<ol class="NOTE">
<li>
<p>As of Jetty 9.2.3 the jetty-osgi-boot-jsp bundle changed to using Apache Jasper as the JSP implementation.
Prior to this the Glassfish Jasper implementation was used, which had a different set of dependencies - pay careful attention to the jars listed both at the top of this page and in this section, as deployment of other jars can cause incomplete or incorrect package resolution in the OSGi container.</p>
</li>
<li>
<p>The order of deployment is important.
Deploy these bundles in the order shown or you may experience strange failures in the compilation of jsps.
This can be hard to diagnose but is almost always caused by the <code>ServletContainerInitializer</code> in the <code>org.eclipse.jetty.apache-jsp</code> bundle for the jsp container not being invoked due to incorrect startup of the annotation jars.</p>
</li>
</ol>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>For the JSTL library, we recommend the use of the implementation from Glassfish, as it has fewer dependencies:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 10. Jars Required for Glassfish JSTL</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Jar</th>
<th class="tableblock halign-left valign-top">Bundle Symbolic Name</th>
<th class="tableblock halign-left valign-top">The <a href="#osgi-jsp">jsp jars</a></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.orbit:javax.servlet.jsp.jstl-1.2.0.v201105211821.jar</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">javax.servlet.jsp.jstl</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>However, if you wish, you may use the JSTL implementation from Apache instead, although you will need to source some dependency jars with suitable OSGi manifests:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 11. Jars Required for Apache JSTL</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Jar</th>
<th class="tableblock halign-left valign-top">Bundle Symbolic Name</th>
<th class="tableblock halign-left valign-top">Location</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">The <a href="#osgi-jsp">jsp jars</a></p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.apache.taglibs:taglibs-standard-spec:jar:1.2.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.apache.taglibs.taglibs-standard-spec</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Distribution lib/apache-jstl</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.apache.taglibs:taglibs-standard-spec:jar:1.2.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.apache.taglibs.standard-impl</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Distribution lib/apache-jstl</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.apache.xalan 2.7.1</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Try
<a href="http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/repository/plugins/org.apache.xalan_2.7.1.v201005080400.jar">Eclipse
Orbit</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.apache.xml.serializer 2.7.1</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Try
<a href="http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/repository/plugins/org.apache.xml.serializer_2.7.1.v201005080400.jar">Eclipse
Orbit</a></p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect4">
<h5 id="_the-jetty-osgi-boot-jsp-jar"><a class="anchor" href="#_the-jetty-osgi-boot-jsp-jar"></a><a class="link" href="#_the-jetty-osgi-boot-jsp-jar">The jetty-osgi-boot-jsp jar</a></h5>
<div class="paragraph">
<p>To be able to use JSPs you will need to also install the <a href="https://repo1.maven.org/maven2/org/eclipse/jetty/osgi/jetty-osgi-boot-jsp/">jetty-osgi-boot-jsp.jar</a> into your OSGi container.
This jar can be obtained from maven central <a href="https://repo1.maven.org/maven2/org/eclipse/jetty/osgi/jetty-osgi-boot-jsp/">here</a>.</p>
</div>
<div class="paragraph">
<p>This bundle acts as a fragment extension to the jetty-osgi-boot.jar and adds in support for using JSP.</p>
</div>
<div class="sect5">
<h6 id="_using-taglibs"><a class="anchor" href="#_using-taglibs"></a><a class="link" href="#_using-taglibs">Using TagLibs</a></h6>
<div class="paragraph">
<p>The Jetty JSP OSGi container will make available the JSTL tag library to all webapps.
If you only use this tag library, then your webapp will work without any further modification.</p>
</div>
<div class="paragraph">
<p>However, if you make use of other taglibs, you will need to ensure that they are installed into the OSGi container, and also define some System properties and/or <code>MANIFEST</code> headers in your webapp.
This is necessary because the classloading regime used by the OSGi container is very different than that used by JSP containers, and the <code>MANIFEST</code> of a normal webapp does not contain enough information for the OSGi environment to allow a JSP container to find and resolve TLDs referenced in the webapp&#8217;s .jsp files.</p>
</div>
<div class="paragraph">
<p>Firstly, lets look at an example of a web bundle&#8217;s modified <code>MANIFEST</code> file so you get an idea of what is required.
This example is a web bundle that uses the Spring servlet framework:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Bundle-SymbolicName: com.acme.sample
Bundle-Name: WebSample
Web-ContextPath: taglibs
Import-Bundle: org.springframework.web.servlet
Require-TldBundle: org.springframework.web.servlet
Bundle-Version: 1.0.0
Import-Package: org.eclipse.virgo.web.dm;version=&quot;[3.0.0,4.0.0)&quot;,org.s
pringframework.context.config;version=&quot;[2.5.6,4.0.0)&quot;,org.springframe
work.stereotype;version=&quot;[2.5.6,4.0.0)&quot;,org.springframework.web.bind.
annotation;version=&quot;[2.5.6,4.0.0)&quot;,org.springframework.web.context;ve
rsion=&quot;[2.5.6,4.0.0)&quot;,org.springframework.web.servlet;version=&quot;[2.5.6
,4.0.0)&quot;,org.springframework.web.servlet.view;version=&quot;[2.5.6,4.0.0)&quot;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <strong>Require-TldBundle</strong> header tells the Jetty OSGi container that this bundle contains TLDs that need to be passed over to the JSP container for processing.
The <strong>Import-Bundle</strong> header ensures that the implementation classes for these TLDs will be available to the webapp on the OSGi classpath.</p>
</div>
<div class="paragraph">
<p>The format of the <strong>Require-TldBundle</strong> header is a comma separated list of one or more symbolic names of bundles containing TLDs.</p>
</div>
</div>
<div class="sect5">
<h6 id="_container-path-taglibs"><a class="anchor" href="#_container-path-taglibs"></a><a class="link" href="#_container-path-taglibs">Container Path Taglibs</a></h6>
<div class="paragraph">
<p>Some TLD jars are required to be found on the Jetty OSGi container&#8217;s classpath, rather than considered part of the web bundle&#8217;s classpath.
For example, this is true of JSTL and Java Server Faces.
The Jetty OSGi container takes care of JSTL for you, but you can control which other jars are considered as part of the container&#8217;s classpath by using the System property <strong>org.eclipse.jetty.osgi.tldbundles</strong>:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">org.eclipse.jetty.osgi.tldbundles</dt>
<dd>
<p>System property defined on the OSGi environment that is a comma separated list of symbolic names of bundles containing taglibs that will be treated as if they are on the container&#8217;s classpath for web bundles.
For example:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">org.eclipse.jetty.osgi.tldbundles=com.acme.special.tags,com.foo.web,org.bar.web.framework</code></pre>
</div>
</div>
<div class="paragraph">
<p>You will still need to define the <strong>Import-Bundle</strong> header in the <code>MANIFEST</code> file for the web bundle to ensure that the TLD bundles are on the OSGi classpath.</p>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Alternatively or additionally, you can define a pattern as a context attribute that will match symbolic bundle names in the OSGi environment containing TLDs that should be considered as discovered from the container&#8217;s classpath.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">org.eclipse.jetty.server.webapp.containerIncludeBundlePattern</dt>
<dd>
<p>This pattern must be specified as a context attribute of the <code>WebAppContext</code> representing the web bundle.
Unless you are deploying your own <code>WebAppContext</code> (see <a href="#services-as-webapps">Deploying Services as Webapps</a>), you won&#8217;t have a reference to the <code>WebAppContext</code> to do this.
In that case, it can be specified on the <code>org.eclipse.jetty.deploy.DeploymentManager</code>, where it will be applied to <em>every</em> webapp deployed by the Jetty OSGi container.
The <code>jetty-osgi-boot.jar</code> contains the default <code>jettyhome/etc/jetty-deploy.xml</code> file where the <code>DeploymentManager</code> is defined.
To set the pattern, you will need to provide your own etc files - see the section on <a href="#customize-jetty-container">customizing the jetty container</a> for how to do this. Here&#8217;s how the <code>jetty-deploy.xml</code> file would look if we defined a pattern that matched all bundle symbolic names ending in "tag" and "web":</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addBean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DeploymentManager</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.deploy.DeploymentManager</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contexts</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Contexts</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setContextAttribute</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>org.eclipse.jetty.server.webapp.ContainerIncludeBundlePattern<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>.*\.tag$|.*\.web$<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Again, you will still need to define suitable <strong>Import-Bundle</strong> headers in your web bundle <code>MANIFEST</code> to ensure that bundles matching the pattern are available on the OSGi class path.</p>
</div>
</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="osgi-annotations"><a class="anchor" href="#osgi-annotations"></a><a class="link" href="#osgi-annotations">Using Annotations/ServletContainerInitializers</a></h4>
<div class="paragraph">
<p>Annotations are very much part of the Servlet 3.0 and 3.1 specifications.
In order to use them with Jetty in OSGi, you will need to deploy some extra jars into your OSGi container:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 12. Jars Required for Annotations</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Jar</th>
<th class="tableblock halign-left valign-top">Bundle Symbolic Name</th>
<th class="tableblock halign-left valign-top">Location</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">The <a href="#spifly">spifly jars</a></p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.ow2.asm:asm-7.0.jar</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.objectweb.asm</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://repo1.maven.org/maven2/org/ow2/asm/asm">Maven central</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.ow2.asm:asm-commons-7.0.jar</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.objectweb.asm.commons</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://repo1.maven.org/maven2/org/ow2/asm/asm-commons">Maven central</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.ow2.asm:asm-tree-7.0.jar</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.objectweb.asm.tree</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://repo1.maven.org/maven2/org/ow2/asm/asm-tree">Maven central</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">javax.annotation:javax.annotation-api-1.2.jar</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">javax.annotation-api</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://repo1.maven.org/maven2/javax/annotation/javax.annotation-api/">Maven
central</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jta api version 1.1.1 (eg
org.apache.geronimo.specs:geronimo-jta_1.1_spec-1.1.1.jar)<sup>*</sup></p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Maven
central</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">javax mail api version 1.4.1 (eg
org.eclipse.jetty.orbit:javax.mail.glassfish-1.4.1.v201005082020.jar)<sup>*</sup></p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Maven central</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-jndi</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.jndi</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Distribution lib/</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-plus</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.plus</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Distribution lib/</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jetty-annotations</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.eclipse.jetty.annotations</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Distribution lib/</p></td>
</tr>
</tbody>
</table>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
If you wish to use JSPs you will need to deploy these annotation-related jars.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
You may be able to deploy later versions or other providers of these specifications, however these particular versions are known to have correct manifests and have been tested and known to work with OSGi.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>Even if your webapp itself does not not use annotations, you may need to deploy these jars because your webapp depends on a Jetty module or a 3rd party library that uses a <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContainerInitializer.html">javax.servlet.ServletContainerInitializer</a>.
This interface requires annotation support.
It is implemented by providers of code that extend the capabilities of the container.
An example of this is the Jetty JSR356 Websocket implementation, although it is being used increasingly commonly in popular libraries like <a href="http://projects.spring.io/spring-framework/">Spring</a>, <a href="https://jersey.java.net/">Jersey</a> and JSP containers.</p>
</div>
<div class="paragraph">
<p>To find <code>ServletContainerInitializers</code> on the classpath, Jetty uses the Java <a href="http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html"><code>ServiceLoader</code></a>
mechanism.
For this to function in OSGi, you will need an OSGi R5 compatible container, and have support for the <a href="http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html">Service Loader Mediator</a>.
Jetty has been tested with the <a href="http://aries.apache.org/modules/spi-fly.html">Aries SpiFly</a> module, which is the reference implementation of the Service Loader Mediator, and is listed in the jars above.</p>
</div>
</div>
<div class="sect3">
<h4 id="_osgi-containers"><a class="anchor" href="#_osgi-containers"></a><a class="link" href="#_osgi-containers">OSGi Containers</a></h4>
<div class="sect4">
<h5 id="_felix"><a class="anchor" href="#_felix"></a><a class="link" href="#_felix">Felix</a></h5>
<div class="paragraph">
<p>The Jetty OSGi integration has been successfully tested against <a href="http://felix.apache.org/">Felix</a> 5.0.0.</p>
</div>
<div class="paragraph">
<p>You will require the following extra Felix services, available as separately downloadable jars:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="http://felix.apache.org/documentation/subprojects/apache-felix-config-admin.html">Felix Configuration Admin Service</a></p>
</li>
<li>
<p><a href="http://felix.apache.org/documentation/subprojects/apache-felix-event-admin.html">Felix Event Admin Service</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Unfortunately, as of Felix 4.x there is a difficultly with the resolution of the <code>javax.transaction</code> package.
A <a href="http://mail-archives.apache.org/mod_mbox/felix-users/201211.mbox/%3CCAPr=90M+5vYjPqAvyTU+gYHr64y_FosBYELeUYcU_rFEJF3Cxw&#64;mail.gmail.com%3E">description of the problem</a> and hint to solving it is described [<a href="http://mail-archives.apache.org/mod_mbox/felix-users/201211.mbox/%3CCAPr=90M+5vYjPqAvyTU+gYHr64y_FosBYELeUYcU_rFEJF3Cxw&#64;mail.gmail.com%3E">here</a>].</p>
</div>
<div class="paragraph">
<p>The simplest solution for this is to extract the <code>default.properties</code> file from the <code>felix.jar</code>, change the declaration of the <code>javax.sql</code> and <code>javax.transaction</code> packages and set the changed lines as the value of the <code>org.osgi.framework.system.packages</code> property in the <code>conf/config.properties</code> file.</p>
</div>
<div class="paragraph">
<p>The <code>default.properties</code> file defines the default <code>org.osgi.framework.system.packages</code> property like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="properties"># Default packages exported by system bundle.
org.osgi.framework.system.packages=org.osgi.framework; version=1.7.0, \
org.osgi.framework.hooks.bundle; version=1.1.0, \
org.osgi.framework.hooks.resolver; version=1.0.0, \
org.osgi.framework.hooks.service; version=1.1.0, \
org.osgi.framework.hooks.weaving; version=1.0.0, \
org.osgi.framework.launch; version=1.1.0, \
org.osgi.framework.namespace; version=1.0.0, \
org.osgi.framework.startlevel; version=1.0.0, \
org.osgi.framework.wiring; version=1.1.0, \
org.osgi.resource; version=1.0.0, \
org.osgi.service.packageadmin; version=1.2.0, \
org.osgi.service.startlevel; version=1.1.0, \
org.osgi.service.url; version=1.0.0, \
org.osgi.util.tracker; version=1.5.1 \
${jre-${java.specification.version}}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The last line must be substituted for one of the definitions further down in the file that is suitable for the jvm you are using.</p>
</div>
<div class="paragraph">
<p>You will take these lines and copy them into the <code>conf/config.properties</code> file, after having replaced the line <code>$\{jre-$\{java.specification.version}}</code> with all of the lines relevant to your version of the jvm.</p>
</div>
<div class="paragraph">
<p>For example, for a 1.7 jvm, you will find this property definition:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="properties">jre-1.7=, \
javax.accessibility;uses:=&quot;javax.swing.text&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.activation;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.activity;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.annotation.processing;uses:=&quot;javax.tools,javax.lang.model,javax.lang.model.element,javax.lang.model.util&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.annotation;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.crypto.interfaces;uses:=&quot;javax.crypto.spec,javax.crypto&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.crypto.spec;uses:=&quot;javax.crypto&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.crypto;uses:=&quot;javax.crypto.spec&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.imageio.event;uses:=&quot;javax.imageio&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.imageio.metadata;uses:=&quot;org.w3c.dom,javax.imageio&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.imageio.plugins.bmp;uses:=&quot;javax.imageio&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.imageio.plugins.jpeg;uses:=&quot;javax.imageio&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.imageio.spi;uses:=&quot;javax.imageio.stream,javax.imageio,javax.imageio.metadata&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.imageio.stream;uses:=&quot;javax.imageio&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.imageio;uses:=&quot;javax.imageio.metadata,javax.imageio.stream,javax.imageio.spi,javax.imageio.event&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.jws.soap;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.jws;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.lang.model.element;uses:=&quot;javax.lang.model.type,javax.lang.model&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.lang.model.type;uses:=&quot;javax.lang.model.element,javax.lang.model&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.lang.model.util;uses:=&quot;javax.lang.model,javax.lang.model.element,javax.annotation.processing,javax.lang.model.type&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.lang.model;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.management.loading;uses:=&quot;javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.management.modelmbean;uses:=&quot;javax.management,javax.management.loading&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.management.monitor;uses:=&quot;javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.management.openmbean;uses:=&quot;javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.management.relation;uses:=&quot;javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.management.remote.rmi;uses:=&quot;javax.management.remote,javax.security.auth,javax.management,javax.management.loading,javax.naming,javax.rmi.ssl,org.omg.CORBA,org.omg.CORBA_2_3.portable,org.omg.CORBA.portable,javax.rmi.CORBA,javax.rmi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.management.remote;uses:=&quot;javax.security.auth,javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.management.timer;uses:=&quot;javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.management;uses:=&quot;javax.management.loading,javax.management.openmbean&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.naming.directory;uses:=&quot;javax.naming&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.naming.event;uses:=&quot;javax.naming,javax.naming.directory&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.naming.ldap;uses:=&quot;javax.naming,javax.naming.directory,javax.net.ssl,javax.naming.event&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.naming.spi;uses:=&quot;javax.naming,javax.naming.directory&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.naming;uses:=&quot;javax.naming.spi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.net.ssl;uses:=&quot;javax.security.cert,javax.security.auth.x500,javax.net&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.net;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.print.attribute.standard;uses:=&quot;javax.print.attribute&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.print.attribute;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.print.event;uses:=&quot;javax.print,javax.print.attribute&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.print;uses:=&quot;javax.print.attribute,javax.print.event,javax.print.attribute.standard&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.rmi.CORBA;uses:=&quot;org.omg.CORBA,org.omg.CORBA_2_3.portable,org.omg.CORBA.portable,org.omg.SendingContext&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.rmi.ssl;uses:=&quot;javax.net,javax.net.ssl&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.rmi;uses:=&quot;org.omg.CORBA,javax.rmi.CORBA&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.script;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.security.auth.callback;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.security.auth.kerberos;uses:=&quot;javax.security.auth,javax.crypto&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.security.auth.login;uses:=&quot;javax.security.auth,javax.security.auth.callback&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.security.auth.spi;uses:=&quot;javax.security.auth.callback,javax.security.auth.login,javax.security.auth&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.security.auth.x500;uses:=&quot;javax.security.auth&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.security.auth;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.security.cert;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.security.sasl;uses:=&quot;javax.security.auth.callback&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.sound.midi.spi;uses:=&quot;javax.sound.midi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.sound.midi;uses:=&quot;javax.sound.midi.spi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.sound.sampled.spi;uses:=&quot;javax.sound.sampled&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.sound.sampled;uses:=&quot;javax.sound.sampled.spi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.sql.rowset.serial;uses:=&quot;javax.sql.rowset&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.sql.rowset.spi;uses:=&quot;javax.sql,javax.naming,javax.sql.rowset&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.sql.rowset;uses:=&quot;javax.sql,javax.sql.rowset.serial,javax.sql.rowset.spi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.sql;uses:=&quot;javax.transaction.xa&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.border;uses:=&quot;javax.swing&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.colorchooser;uses:=&quot;javax.swing,javax.swing.border,javax.swing.event,javax.swing.text&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.event;uses:=&quot;javax.swing,javax.swing.text,javax.swing.table,javax.swing.tree,javax.swing.undo&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.filechooser;uses:=&quot;javax.swing&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.plaf.basic;uses:=&quot;javax.swing.border,javax.swing,javax.swing.plaf,javax.swing.text,javax.swing.event,javax.swing.colorchooser,javax.accessibility,javax.swing.filechooser,javax.swing.text.html,javax.sound.sampled,javax.swing.table,javax.swing.plaf.synth,javax.swing.tree&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.plaf.metal;uses:=&quot;javax.swing.plaf,javax.swing,javax.swing.border,javax.swing.text,javax.swing.plaf.basic,javax.swing.filechooser,javax.swing.event,javax.swing.tree&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.plaf.multi;uses:=&quot;javax.accessibility,javax.swing,javax.swing.plaf,javax.swing.filechooser,javax.swing.text,javax.swing.tree&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.plaf.nimbus;uses:=&quot;javax.swing,javax.swing.plaf,javax.swing.border,javax.swing.plaf.synth&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.plaf.synth;uses:=&quot;javax.swing,javax.swing.plaf,javax.swing.text,javax.swing.border,javax.swing.plaf.basic,javax.swing.colorchooser,javax.swing.event,javax.xml.parsers,org.xml.sax,org.xml.sax.helpers,javax.swing.table,javax.swing.tree&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.plaf;uses:=&quot;javax.swing,javax.swing.border,javax.accessibility,javax.swing.filechooser,javax.swing.text,javax.swing.tree&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.table;uses:=&quot;javax.swing.event,javax.swing.plaf,javax.swing.border,javax.swing,javax.accessibility&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.text.html.parser;uses:=&quot;javax.swing.text,javax.swing.text.html&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.text.html;uses:=&quot;javax.swing.event,javax.swing.text,javax.accessibility,javax.swing,javax.swing.plaf,javax.swing.border,javax.swing.undo&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.text.rtf;uses:=&quot;javax.swing.text&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.text;uses:=&quot;javax.swing.event,javax.swing.tree,javax.swing.undo,javax.swing,javax.swing.plaf,javax.swing.plaf.basic,javax.print,javax.print.attribute,javax.accessibility,javax.swing.text.html&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.tree;uses:=&quot;javax.swing.event,javax.swing,javax.swing.border,javax.swing.plaf,javax.swing.plaf.basic&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing.undo;uses:=&quot;javax.swing,javax.swing.event&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.swing;uses:=&quot;javax.swing.event,javax.accessibility,javax.swing.text,javax.swing.plaf,javax.swing.border,javax.swing.tree,javax.swing.table,javax.swing.colorchooser,javax.swing.plaf.basic,javax.swing.text.html,javax.swing.filechooser,javax.print,javax.print.attribute,javax.swing.plaf.metal&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.tools;uses:=&quot;javax.lang.model.element,javax.annotation.processing,javax.lang.model&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.transaction.xa;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.transaction;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.bind.annotation.adapters;uses:=&quot;javax.xml.bind&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.bind.annotation;uses:=&quot;javax.xml.transform,javax.xml.bind,javax.xml.parsers,javax.xml.transform.dom,org.w3c.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.bind.attachment;uses:=&quot;javax.activation&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.bind.helpers;uses:=&quot;javax.xml.bind.annotation.adapters,javax.xml.transform.dom,org.w3c.dom,org.xml.sax,javax.xml.bind.attachment,javax.xml.stream,javax.xml.transform,javax.xml.transform.stream,javax.xml.validation,javax.xml.transform.sax,javax.xml.bind,javax.xml.parsers&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.bind.util;uses:=&quot;javax.xml.transform.sax,javax.xml.bind,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.bind;uses:=&quot;javax.xml.validation,javax.xml.namespace,javax.xml.datatype,javax.xml.transform,javax.xml.bind.annotation,javax.xml.transform.stream,org.w3c.dom,javax.xml.bind.attachment,javax.xml.stream,javax.xml.bind.annotation.adapters,org.xml.sax&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.crypto.dom;uses:=&quot;javax.xml.crypto,org.w3c.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.crypto.dsig.dom;uses:=&quot;javax.xml.crypto.dsig,javax.xml.crypto,org.w3c.dom,javax.xml.crypto.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.crypto.dsig.keyinfo;uses:=&quot;javax.xml.crypto&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.crypto.dsig.spec;uses:=&quot;javax.xml.crypto&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.crypto.dsig;uses:=&quot;javax.xml.crypto,javax.xml.crypto.dsig.spec,javax.xml.crypto.dsig.keyinfo&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.crypto;uses:=&quot;javax.xml.crypto.dsig.keyinfo&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.datatype;uses:=&quot;javax.xml.namespace&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.namespace;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.parsers;uses:=&quot;javax.xml.validation,org.w3c.dom,org.xml.sax,org.xml.sax.helpers&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.soap;uses:=&quot;javax.activation,javax.xml.namespace,org.w3c.dom,javax.xml.transform.dom,javax.xml.transform&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.stream.events;uses:=&quot;javax.xml.namespace,javax.xml.stream&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.stream.util;uses:=&quot;javax.xml.stream,javax.xml.stream.events,javax.xml.namespace&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.stream;uses:=&quot;javax.xml.stream.events,javax.xml.namespace,javax.xml.stream.util,javax.xml.transform&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.transform.dom;uses:=&quot;javax.xml.transform,org.w3c.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.transform.sax;uses:=&quot;org.xml.sax.ext,javax.xml.transform,org.xml.sax,javax.xml.transform.stream&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.transform.stax;uses:=&quot;javax.xml.stream,javax.xml.transform,javax.xml.stream.events&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.transform.stream;uses:=&quot;javax.xml.transform&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.transform;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.validation;uses:=&quot;org.w3c.dom.ls,javax.xml.transform,javax.xml.transform.stream,org.xml.sax,org.w3c.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.ws.handler.soap;uses:=&quot;javax.xml.ws.handler,javax.xml.namespace,javax.xml.soap,javax.xml.bind&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.ws.handler;uses:=&quot;javax.xml.ws,javax.xml.namespace&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.ws.http;uses:=&quot;javax.xml.ws&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.ws.soap;uses:=&quot;javax.xml.ws.spi,javax.xml.ws,javax.xml.soap&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.ws.spi.http;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.ws.spi;uses:=&quot;javax.xml.ws,javax.xml.ws.wsaddressing,javax.xml.transform,org.w3c.dom,javax.xml.namespace,javax.xml.ws.handler,javax.xml.bind&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.ws.wsaddressing;uses:=&quot;javax.xml.bind.annotation,javax.xml.namespace,org.w3c.dom,javax.xml.transform,javax.xml.bind,javax.xml.ws,javax.xml.ws.spi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.ws;uses:=&quot;javax.xml.ws.handler,javax.xml.ws.spi,javax.xml.ws.spi.http,javax.xml.transform,org.w3c.dom,javax.xml.bind.annotation,javax.xml.transform.stream,javax.xml.bind,javax.xml.namespace&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml.xpath;uses:=&quot;org.xml.sax,javax.xml.namespace&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
javax.xml;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.ietf.jgss;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.CORBA.DynAnyPackage;uses:=&quot;org.omg.CORBA&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.CORBA.ORBPackage;uses:=&quot;org.omg.CORBA&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.CORBA.TypeCodePackage;uses:=&quot;org.omg.CORBA&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.CORBA.portable;uses:=&quot;org.omg.CORBA,org.omg.CORBA_2_3.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.CORBA;uses:=&quot;org.omg.CORBA.portable,org.omg.CORBA.DynAnyPackage,org.omg.CORBA.ORBPackage,org.omg.CORBA_2_3.portable,org.omg.CORBA.TypeCodePackage&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.CORBA_2_3.portable;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.CORBA_2_3;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.CosNaming.NamingContextExtPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.CosNaming.NamingContextPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable,org.omg.CosNaming&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.CosNaming;uses:=&quot;org.omg.CORBA.portable,org.omg.CORBA,org.omg.PortableServer,org.omg.CosNaming.NamingContextPackage,org.omg.CosNaming.NamingContextExtPackage&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.Dynamic;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.DynamicAny.DynAnyFactoryPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.DynamicAny.DynAnyPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.DynamicAny;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable,org.omg.DynamicAny.DynAnyFactoryPackage,org.omg.DynamicAny.DynAnyPackage&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.IOP.CodecFactoryPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.IOP.CodecPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.IOP;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable,org.omg.IOP.CodecFactoryPackage,org.omg.IOP.CodecPackage&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.Messaging;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.PortableInterceptor.ORBInitInfoPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.PortableInterceptor;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable,org.omg.IOP,org.omg.PortableInterceptor.ORBInitInfoPackage,org.omg.CORBA_2_3.portable,org.omg.Dynamic&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.PortableServer.CurrentPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.PortableServer.POAManagerPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.PortableServer.POAPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.PortableServer.ServantLocatorPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.PortableServer.portable;uses:=&quot;org.omg.CORBA,org.omg.PortableServer&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.PortableServer;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable,org.omg.PortableServer.CurrentPackage,org.omg.PortableServer.POAManagerPackage,org.omg.PortableServer.POAPackage,org.omg.PortableServer.portable,org.omg.CORBA_2_3,org.omg.PortableServer.ServantLocatorPackage&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.SendingContext;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.omg.stub.java.rmi;uses:=&quot;javax.rmi.CORBA&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.w3c.dom.bootstrap;uses:=&quot;org.w3c.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.w3c.dom.events;uses:=&quot;org.w3c.dom,org.w3c.dom.views&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.w3c.dom.ls;uses:=&quot;org.w3c.dom,org.w3c.dom.events,org.w3c.dom.traversal&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.w3c.dom;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.xml.sax.ext;uses:=&quot;org.xml.sax,org.xml.sax.helpers&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.xml.sax.helpers;uses:=&quot;org.xml.sax&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, \
org.xml.sax;version=&quot;0.0.0.1_007_JavaSE&quot;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Remove the definition for the <code>javax.transaction</code> packages, and remove the <code>uses:=</code> clause for the <code>javax.sql</code> packages (but leaving the <code>version</code> clause). Concatenate all the lines together.
You&#8217;ll wind up with something like this in your <code>conf/config.properties</code> file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="properties">org.osgi.framework.system.packages=org.osgi.framework;version=1.7.0, org.osgi.framework.hooks.bundle;version=1.1.0, org.osgi.framework.hooks.resolver;version=1.0.0, org.osgi.framework.hooks.service;version=1.1.0, org.osgi.framework.hooks.weaving;version=1.0.0, org.osgi.framework.launch;version=1.1.0, org.osgi.framework.namespace;version=1.0.0, org.osgi.framework.startlevel;version=1.0.0, org.osgi.framework.wiring;version=1.1.0, org.osgi.resource;version=1.0.0, org.osgi.service.packageadmin; version=1.2.0, org.osgi.service.startlevel; version=1.1.0, org.osgi.service.url;version=1.0.0, org.osgi.util.tracker;version=1.5.1 javax.accessibility;uses:=&quot;javax.swing.text&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.activation;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.activity;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.annotation.processing;uses:=&quot;javax.tools,javax.lang.model,javax.lang.model.element,javax.lang.model.util&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.annotation;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.crypto.interfaces;uses:=&quot;javax.crypto.spec,javax.crypto&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.crypto.spec;uses:=&quot;javax.crypto&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.crypto;uses:=&quot;javax.crypto.spec&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.imageio.event;uses:=&quot;javax.imageio&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.imageio.metadata;uses:=&quot;org.w3c.dom,javax.imageio&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.imageio.plugins.bmp;uses:=&quot;javax.imageio&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.imageio.plugins.jpeg;uses:=&quot;javax.imageio&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.imageio.spi;uses:=&quot;javax.imageio.stream,javax.imageio,javax.imageio.metadata&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.imageio.stream;uses:=&quot;javax.imageio&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.imageio;uses:=&quot;javax.imageio.metadata,javax.imageio.stream,javax.imageio.spi,javax.imageio.event&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.jws.soap;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.jws;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.lang.model.element;uses:=&quot;javax.lang.model.type,javax.lang.model&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.lang.model.type;uses:=&quot;javax.lang.model.element,javax.lang.model&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.lang.model.util;uses:=&quot;javax.lang.model,javax.lang.model.element,javax.annotation.processing,javax.lang.model.type&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.lang.model;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.management.loading;uses:=&quot;javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.management.modelmbean;uses:=&quot;javax.management,javax.management.loading&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.management.monitor;uses:=&quot;javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.management.openmbean;uses:=&quot;javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.management.relation;uses:=&quot;javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.management.remote.rmi;uses:=&quot;javax.management.remote,javax.security.auth,javax.management,javax.management.loading,javax.naming,javax.rmi.ssl,org.omg.CORBA,org.omg.CORBA_2_3.portable,org.omg.CORBA.portable,javax.rmi.CORBA,javax.rmi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.management.remote;uses:=&quot;javax.security.auth,javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.management.timer;uses:=&quot;javax.management&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.management;uses:=&quot;javax.management.loading,javax.management.openmbean&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.naming.directory;uses:=&quot;javax.naming&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.naming.event;uses:=&quot;javax.naming,javax.naming.directory&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.naming.ldap;uses:=&quot;javax.naming,javax.naming.directory,javax.net.ssl,javax.naming.event&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.naming.spi;uses:=&quot;javax.naming,javax.naming.directory&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.naming;uses:=&quot;javax.naming.spi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.net.ssl;uses:=&quot;javax.security.cert,javax.security.auth.x500,javax.net&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.net;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.print.attribute.standard;uses:=&quot;javax.print.attribute&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.print.attribute;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.print.event;uses:=&quot;javax.print,javax.print.attribute&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.print;uses:=&quot;javax.print.attribute,javax.print.event,javax.print.attribute.standard&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.rmi.CORBA;uses:=&quot;org.omg.CORBA,org.omg.CORBA_2_3.portable,org.omg.CORBA.portable,org.omg.SendingContext&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.rmi.ssl;uses:=&quot;javax.net,javax.net.ssl&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.rmi;uses:=&quot;org.omg.CORBA,javax.rmi.CORBA&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.script;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.security.auth.callback;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.security.auth.kerberos;uses:=&quot;javax.security.auth,javax.crypto&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.security.auth.login;uses:=&quot;javax.security.auth,javax.security.auth.callback&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.security.auth.spi;uses:=&quot;javax.security.auth.callback,javax.security.auth.login,javax.security.auth&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.security.auth.x500;uses:=&quot;javax.security.auth&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.security.auth;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.security.cert;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.security.sasl;uses:=&quot;javax.security.auth.callback&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.sound.midi.spi;uses:=&quot;javax.sound.midi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.sound.midi;uses:=&quot;javax.sound.midi.spi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.sound.sampled.spi;uses:=&quot;javax.sound.sampled&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.sound.sampled;uses:=&quot;javax.sound.sampled.spi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.sql.rowset.serial;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.sql.rowset.spi;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.sql.rowset;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.sql;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.border;uses:=&quot;javax.swing&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.colorchooser;uses:=&quot;javax.swing,javax.swing.border,javax.swing.event,javax.swing.text&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.event;uses:=&quot;javax.swing,javax.swing.text,javax.swing.table,javax.swing.tree,javax.swing.undo&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.filechooser;uses:=&quot;javax.swing&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.plaf.basic;uses:=&quot;javax.swing.border,javax.swing,javax.swing.plaf,javax.swing.text,javax.swing.event,javax.swing.colorchooser,javax.accessibility,javax.swing.filechooser,javax.swing.text.html,javax.sound.sampled,javax.swing.table,javax.swing.plaf.synth,javax.swing.tree&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.plaf.metal;uses:=&quot;javax.swing.plaf,javax.swing,javax.swing.border,javax.swing.text,javax.swing.plaf.basic,javax.swing.filechooser,javax.swing.event,javax.swing.tree&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.plaf.multi;uses:=&quot;javax.accessibility,javax.swing,javax.swing.plaf,javax.swing.filechooser,javax.swing.text,javax.swing.tree&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.plaf.nimbus;uses:=&quot;javax.swing,javax.swing.plaf,javax.swing.border,javax.swing.plaf.synth&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.plaf.synth;uses:=&quot;javax.swing,javax.swing.plaf,javax.swing.text,javax.swing.border,javax.swing.plaf.basic,javax.swing.colorchooser,javax.swing.event,javax.xml.parsers,org.xml.sax,org.xml.sax.helpers,javax.swing.table,javax.swing.tree&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.plaf;uses:=&quot;javax.swing,javax.swing.border,javax.accessibility,javax.swing.filechooser,javax.swing.text,javax.swing.tree&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.table;uses:=&quot;javax.swing.event,javax.swing.plaf,javax.swing.border,javax.swing,javax.accessibility&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.text.html.parser;uses:=&quot;javax.swing.text,javax.swing.text.html&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.text.html;uses:=&quot;javax.swing.event,javax.swing.text,javax.accessibility,javax.swing,javax.swing.plaf,javax.swing.border,javax.swing.undo&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.text.rtf;uses:=&quot;javax.swing.text&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.text;uses:=&quot;javax.swing.event,javax.swing.tree,javax.swing.undo,javax.swing,javax.swing.plaf,javax.swing.plaf.basic,javax.print,javax.print.attribute,javax.accessibility,javax.swing.text.html&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.tree;uses:=&quot;javax.swing.event,javax.swing,javax.swing.border,javax.swing.plaf,javax.swing.plaf.basic&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing.undo;uses:=&quot;javax.swing,javax.swing.event&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.swing;uses:=&quot;javax.swing.event,javax.accessibility,javax.swing.text,javax.swing.plaf,javax.swing.border,javax.swing.tree,javax.swing.table,javax.swing.colorchooser,javax.swing.plaf.basic,javax.swing.text.html,javax.swing.filechooser,javax.print,javax.print.attribute,javax.swing.plaf.metal&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.tools;uses:=&quot;javax.lang.model.element,javax.annotation.processing,javax.lang.model&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.bind.annotation.adapters;uses:=&quot;javax.xml.bind&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.bind.annotation;uses:=&quot;javax.xml.transform,javax.xml.bind,javax.xml.parsers,javax.xml.transform.dom,org.w3c.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.bind.attachment;uses:=&quot;javax.activation&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.bind.helpers;uses:=&quot;javax.xml.bind.annotation.adapters,javax.xml.transform.dom,org.w3c.dom,org.xml.sax,javax.xml.bind.attachment,javax.xml.stream,javax.xml.transform,javax.xml.transform.stream,javax.xml.validation,javax.xml.transform.sax,javax.xml.bind,javax.xml.parsers&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.bind.util;uses:=&quot;javax.xml.transform.sax,javax.xml.bind,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.bind;uses:=&quot;javax.xml.validation,javax.xml.namespace,javax.xml.datatype,javax.xml.transform,javax.xml.bind.annotation,javax.xml.transform.stream,org.w3c.dom,javax.xml.bind.attachment,javax.xml.stream,javax.xml.bind.annotation.adapters,org.xml.sax&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.crypto.dom;uses:=&quot;javax.xml.crypto,org.w3c.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.crypto.dsig.dom;uses:=&quot;javax.xml.crypto.dsig,javax.xml.crypto,org.w3c.dom,javax.xml.crypto.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.crypto.dsig.keyinfo;uses:=&quot;javax.xml.crypto&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.crypto.dsig.spec;uses:=&quot;javax.xml.crypto&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.crypto.dsig;uses:=&quot;javax.xml.crypto,javax.xml.crypto.dsig.spec,javax.xml.crypto.dsig.keyinfo&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.crypto;uses:=&quot;javax.xml.crypto.dsig.keyinfo&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.datatype;uses:=&quot;javax.xml.namespace&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.namespace;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.parsers;uses:=&quot;javax.xml.validation,org.w3c.dom,org.xml.sax,org.xml.sax.helpers&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.soap;uses:=&quot;javax.activation,javax.xml.namespace,org.w3c.dom,javax.xml.transform.dom,javax.xml.transform&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.stream.events;uses:=&quot;javax.xml.namespace,javax.xml.stream&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.stream.util;uses:=&quot;javax.xml.stream,javax.xml.stream.events,javax.xml.namespace&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.stream;uses:=&quot;javax.xml.stream.events,javax.xml.namespace,javax.xml.stream.util,javax.xml.transform&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.transform.dom;uses:=&quot;javax.xml.transform,org.w3c.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.transform.sax;uses:=&quot;org.xml.sax.ext,javax.xml.transform,org.xml.sax,javax.xml.transform.stream&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.transform.stax;uses:=&quot;javax.xml.stream,javax.xml.transform,javax.xml.stream.events&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.transform.stream;uses:=&quot;javax.xml.transform&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.transform;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.validation;uses:=&quot;org.w3c.dom.ls,javax.xml.transform,javax.xml.transform.stream,org.xml.sax,org.w3c.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.ws.handler.soap;uses:=&quot;javax.xml.ws.handler,javax.xml.namespace,javax.xml.soap,javax.xml.bind&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.ws.handler;uses:=&quot;javax.xml.ws,javax.xml.namespace&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.ws.http;uses:=&quot;javax.xml.ws&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.ws.soap;uses:=&quot;javax.xml.ws.spi,javax.xml.ws,javax.xml.soap&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.ws.spi.http;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.ws.spi;uses:=&quot;javax.xml.ws,javax.xml.ws.wsaddressing,javax.xml.transform,org.w3c.dom,javax.xml.namespace,javax.xml.ws.handler,javax.xml.bind&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.ws.wsaddressing;uses:=&quot;javax.xml.bind.annotation,javax.xml.namespace,org.w3c.dom,javax.xml.transform,javax.xml.bind,javax.xml.ws,javax.xml.ws.spi&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.ws;uses:=&quot;javax.xml.ws.handler,javax.xml.ws.spi,javax.xml.ws.spi.http,javax.xml.transform,org.w3c.dom,javax.xml.bind.annotation,javax.xml.transform.stream,javax.xml.bind,javax.xml.namespace&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml.xpath;uses:=&quot;org.xml.sax,javax.xml.namespace&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, javax.xml;version=&quot;0.0.0.1_007_JavaSE&quot;, org.ietf.jgss;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.CORBA.DynAnyPackage;uses:=&quot;org.omg.CORBA&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.CORBA.ORBPackage;uses:=&quot;org.omg.CORBA&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.CORBA.TypeCodePackage;uses:=&quot;org.omg.CORBA&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.CORBA.portable;uses:=&quot;org.omg.CORBA,org.omg.CORBA_2_3.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.CORBA;uses:=&quot;org.omg.CORBA.portable,org.omg.CORBA.DynAnyPackage,org.omg.CORBA.ORBPackage,org.omg.CORBA_2_3.portable,org.omg.CORBA.TypeCodePackage&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.CORBA_2_3.portable;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.CORBA_2_3;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.CosNaming.NamingContextExtPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.CosNaming.NamingContextPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable,org.omg.CosNaming&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.CosNaming;uses:=&quot;org.omg.CORBA.portable,org.omg.CORBA,org.omg.PortableServer,org.omg.CosNaming.NamingContextPackage,org.omg.CosNaming.NamingContextExtPackage&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.Dynamic;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.DynamicAny.DynAnyFactoryPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.DynamicAny.DynAnyPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.DynamicAny;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable,org.omg.DynamicAny.DynAnyFactoryPackage,org.omg.DynamicAny.DynAnyPackage&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.IOP.CodecFactoryPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.IOP.CodecPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.IOP;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable,org.omg.IOP.CodecFactoryPackage,org.omg.IOP.CodecPackage&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.Messaging;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.PortableInterceptor.ORBInitInfoPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.PortableInterceptor;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable,org.omg.IOP,org.omg.PortableInterceptor.ORBInitInfoPackage,org.omg.CORBA_2_3.portable,org.omg.Dynamic&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.PortableServer.CurrentPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.PortableServer.POAManagerPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.PortableServer.POAPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.PortableServer.ServantLocatorPackage;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.PortableServer.portable;uses:=&quot;org.omg.CORBA,org.omg.PortableServer&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.PortableServer;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable,org.omg.PortableServer.CurrentPackage,org.omg.PortableServer.POAManagerPackage,org.omg.PortableServer.POAPackage,org.omg.PortableServer.portable,org.omg.CORBA_2_3,org.omg.PortableServer.ServantLocatorPackage&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.SendingContext;uses:=&quot;org.omg.CORBA,org.omg.CORBA.portable&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.omg.stub.java.rmi;uses:=&quot;javax.rmi.CORBA&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.w3c.dom.bootstrap;uses:=&quot;org.w3c.dom&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.w3c.dom.events;uses:=&quot;org.w3c.dom,org.w3c.dom.views&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.w3c.dom.ls;uses:=&quot;org.w3c.dom,org.w3c.dom.events,org.w3c.dom.traversal&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.w3c.dom;version=&quot;0.0.0.1_007_JavaSE&quot;, org.xml.sax.ext;uses:=&quot;org.xml.sax,org.xml.sax.helpers&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.xml.sax.helpers;uses:=&quot;org.xml.sax&quot;;version=&quot;0.0.0.1_007_JavaSE&quot;, org.xml.sax;version=&quot;0.0.0.1_007_JavaSE&quot;</code></pre>
</div>
</div>
<div class="paragraph">
<p>You should now be able to start Felix, and deploy all the jars listed on this page.
You should see output similar to this on the console, using the <code>felix:lb</code> command:</p>
</div>
<div class="literalblock">
<div class="content">
<pre> ID|State |Level|Name
0|Active | 0|System Bundle (4.4.1)
1|Active | 1|ASM (7.0)
2|Active | 1|ASM commons classes (7.0)
3|Active | 1|ASM Tree class visitor (7.0)
4|Active | 1|geronimo-jta_1.1_spec (1.1.1)
5|Active | 1|javax.annotation API (1.2.0)
6|Active | 1|javax.mail bundle from Glassfish (1.4.1.v201005082020)
7|Active | 1|Java Server Pages Standard Tag Library API Bundle (1.2.0.v201105211821)
8|Active | 1|JavaServer Pages (TM) TagLib Implementation (1.2.2)
9|Active | 1|Jetty :: Servlet Annotations ({VERSION})
10|Active | 1|Jetty :: Deployers ({VERSION})
11|Active | 1|Jetty :: Http Utility ({VERSION})
12|Active | 1|Jetty :: IO Utility ({VERSION})
13|Active | 1|Jetty :: JNDI Naming ({VERSION})
14|Active | 1|Jetty :: OSGi :: Boot ({VERSION})
15|Resolved | 1|Jetty-OSGi-Jasper Integration ({VERSION})
16|Active | 1|Jetty Servlet API and Schemas for OSGi (3.1.0)
17|Active | 1|Jetty :: Plus ({VERSION})
18|Active | 1|Jetty :: Security ({VERSION})
19|Active | 1|Jetty :: Server Core ({VERSION})
20|Active | 1|Jetty :: Servlet Handling ({VERSION})
21|Active | 1|Jetty :: Utility Servlets and Filters ({VERSION})
22|Active | 1|Jetty :: Utilities ({VERSION})
23|Active | 1|Jetty :: Webapp Application Support ({VERSION})
24|Active | 1|Jetty :: XML utilities ({VERSION})
25|Active | 1|Apache Aries SPI Fly Dynamic Weaving Bundle (1.2)
27|Active | 1|Apache Felix Bundle Repository (2.0.2)
28|Active | 1|Apache Felix Configuration Admin Service (1.8.0)
29|Active | 1|Apache Felix EventAdmin (1.3.2)
30|Active | 1|Apache Felix Gogo Command (0.14.0)
31|Active | 1|Apache Felix Gogo Runtime (0.12.1)
32|Active | 1|Apache Felix Gogo Shell (0.10.0)
33|Active | 1|Apache Felix Log Service (1.0.1)
34|Active | 1|Jetty :: Apache JSP ({VERSION})
35|Active | 1|Eclipse Compiler for Java(TM) (3.8.2.v20130121-145325)
36|Active | 1|Mortbay EL API and Implementation (8.5.33.1)
37|Active | 1|Mortbay Jasper (8.5.33.1)</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_eclipse"><a class="anchor" href="#_eclipse"></a><a class="link" href="#_eclipse">Eclipse</a></h5>
<div class="paragraph">
<p>The Jetty OSGi integration has been successfully tested against <a href="https://www.eclipse.org/equinox/">Equinox</a> Mars RC1.</p>
</div>
<div class="paragraph">
<p>Ensure that these services are present:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://www.eclipse.org/equinox/bundles/">Configuration Admin</a></p>
</li>
<li>
<p><a href="https://www.eclipse.org/equinox/bundles/">Event Admin</a></p>
</li>
</ul>
</div>
<div class="sect5">
<h6 id="_eclipse-update-site"><a class="anchor" href="#_eclipse-update-site"></a><a class="link" href="#_eclipse-update-site">Eclipse Update Site</a></h6>
<div class="paragraph">
<p>There is a list of Eclipse P2 sites for the jetty releases maintained at <a href="http://download.eclipse.org/jetty/updates/jetty-bundles-9.x/" class="bare">http://download.eclipse.org/jetty/updates/jetty-bundles-9.x/</a></p>
</div>
<div class="paragraph">
<p>Each P2 repo has one big feature group that defines most of the Jetty jars.
<strong>Beware: No 3rd party dependency jars are included, so you will need to have installed the dependencies listed previously in this document.</strong></p>
</div>
<div class="paragraph">
<p>In addition, as the feature group includes websocket, you will need to download and have installed the <code>javax.websocket-api</code> jar:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 13. Extra Jars Required for Websocket</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Jar</th>
<th class="tableblock halign-left valign-top">Bundle Symbolic Name</th>
<th class="tableblock halign-left valign-top">Location</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">javax.websocket-api</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">javax.websocket-api</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://repo1.maven.org/maven2/javax/websocket/">Maven
central</a></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="framework-metro"><a class="anchor" href="#framework-metro"></a><a class="link" href="#framework-metro">Metro</a></h3>
<div class="paragraph">
<p><a href="https://metro.java.net/">Metro</a> is the reference implementation for <a href="http://jcp.org/en/jsr/detail?id=109">web services</a>.
You can easily use Metro with Jetty to integrate web services with your web applications.</p>
</div>
<div class="sect3">
<h4 id="metro-setup-distro"><a class="anchor" href="#metro-setup-distro"></a><a class="link" href="#metro-setup-distro">Metro Setup</a></h4>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><a href="https://metro.java.net/latest/download.html">Download</a> the Metro distribution and unpack it to your disk.
We&#8217;ll refer to the unpacked location as <code>$metro.home</code>.</p>
</li>
<li>
<p>Create the directory <code>$jetty.home/lib/metro</code></p>
</li>
<li>
<p>Copy the jars from $metro.home/lib to <code>$jetty.home/lib/metro</code></p>
</li>
<li>
<p>Edit the start.ini file and add an OPTION line for metro near the end.</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">OPTIONS=metro</code></pre>
</div>
</div>
</li>
</ol>
</div>
<div class="paragraph">
<p>That&#8217;s all the setup you need to do to integrate Jetty and Metro.</p>
</div>
<div class="paragraph">
<p>Now read the <a href="https://metro.java.net/discover/">Metro documentation</a> on <a href="https://metro.java.net/getting-started/">how to create web services</a>.
The Metro distribution you downloaded should also contain several example web applications in the $metro.home/samples directory that you can build and deploy to Jetty (simply by copying the war file produced by the build).</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of the log output from Jetty when one of the sample Metro wars (from <code>$metro.home/samples/async</code>) is deployed to Jetty:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[2093] java -jar start.jar
2013-07-26 15:47:53.480:INFO:oejs.Server:main: jetty-9.0.4.v20130625
2013-07-26 15:47:53.549:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/home/user/jetty-home-10.0.10/webapps/] at interval 1
Jul 26, 2013 3:47:53 PM com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextInitialized
INFO: WSSERVLET12: JAX-WS context listener initializing
Jul 26, 2013 3:47:56 PM com.sun.xml.ws.server.MonitorBase createRoot
INFO: Metro monitoring rootname successfully set to: com.sun.metro:pp=/,type=WSEndpoint,name=/metro-async-AddNumbersService-AddNumbersImplPort
Jul 26, 2013 3:47:56 PM com.sun.xml.ws.transport.http.servlet.WSServletDelegate &lt;init&gt;
INFO: WSSERVLET14: JAX-WS servlet initializing
2013-07-26 15:47:56.800:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@75707c77{/metro-async,file:/tmp/jetty-0.0.0.0-8080-metro-async.war-_metro-async-any-/webapp/,AVAILABLE}{/metro-async.war}
2013-07-26 15:47:56.853:INFO:oejs.ServerConnector:main: Started ServerConnector@47dce809{HTTP/1.1}{0.0.0.0:8080}</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="introduction"><a class="anchor" href="#introduction"></a><a class="link" href="#introduction">Introducing Jetty</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="what-is-jetty"><a class="anchor" href="#what-is-jetty"></a><a class="link" href="#what-is-jetty">What is Jetty?</a></h3>
<div class="paragraph">
<p>Eclipse Jetty is an open-source project providing an HTTP server, HTTP client, and servlet container.</p>
</div>
<div class="paragraph">
<p>The Jetty documentation is broken up in to four parts:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The <a href="{GSTARTEDGUIDE}">Getting Started Guide</a> emphasizes beginning to use Jetty.
It provides information about what Jetty is and where you can download it, and where to find Jetty in repositories like Central Maven.
It also provides a Quick Start guide on how to get Jetty up and running as well as an overview of how and what to configure in Jetty.</p>
</li>
<li>
<p>The <a href="{OPGUIDE}">Operations Guide</a> details configuring Jetty as a distributed package at a more granular level.
From server startup to session management, logging, HTTP/2 support and Jetty optimization, these chapters will help administrators get the most out of their distributed Jetty server instances.
This section also covers configuring many of the most common servlet container features such as JNDI and JMX.</p>
</li>
<li>
<p>Aimed at advanced users of Jetty, the <a href="{PROGGUIDE}">Programming Guide</a> focuses on Jetty development.
A large portion of this section is focused on using Jetty as an embedded server in existing applications.
It contains several examples and how-to guides for making the most out of the Jetty framework.
This section also includes a guide on using the Jetty Maven plugin as well as information on debugging Jetty.</p>
</li>
<li>
<p>The <a href="#{CONTRIBGUIDE}">Contribution Guide</a> is aimed at those who want to contribute to the Jetty open source project.
It includes instructions on interacting with the community, how to raise bugs, and how to report security issues.
In addition, it also details source control and build information for the project.</p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="what-jetty-version"><a class="anchor" href="#what-jetty-version"></a><a class="link" href="#what-jetty-version">What Version Do I Use?</a></h3>
<div class="paragraph">
<p>Jetty 10 and 11 are the most recent versions of Jetty and has a great many improvements over previous versions.
This documentation which focuses on Jetty 10.
While many people continue to use older versions of Jetty, we generally recommend using Jetty 10 or 11 (more on the differences later) as they represent the version of Jetty that we will actively maintain and improve over the next few years.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
It is important that only stable releases are used in production environments.
Versions that have been deprecated or are released as Milestones (M) or Release Candidates (RC) are not suitable for production as they may contain security flaws or incomplete/non-functioning feature sets.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 14. Jetty Versions</caption>
<colgroup>
<col style="width: 12%;">
<col style="width: 9%;">
<col style="width: 15%;">
<col style="width: 6%;">
<col style="width: 21%;">
<col style="width: 10%;">
<col style="width: 6%;">
<col style="width: 21%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Version</th>
<th class="tableblock halign-left valign-top">Year</th>
<th class="tableblock halign-left valign-top">Home</th>
<th class="tableblock halign-left valign-top">Min JVM</th>
<th class="tableblock halign-left valign-top">Protocols</th>
<th class="tableblock halign-left valign-top">Servlet</th>
<th class="tableblock halign-left valign-top">JSP</th>
<th class="tableblock halign-left valign-top">Status</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">11</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2020-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Eclipse</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">11 <sup>(2)</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), WebSocket (RFC 6455, JSR 356), FastCGI, <strong>JakartaEE Namespace</strong><sup>(1)</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">5.0.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3.0.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Stable</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">10</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2019-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Eclipse</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">11 <sup>(2)</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), WebSocket (RFC 6455, JSR 356), FastCGI</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">4.0.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.2</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Stable</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">9.4</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2016-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Eclipse</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.8</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), WebSocket (RFC 6455, JSR 356), FastCGI</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Stable</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">9.3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2015-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Eclipse</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.8 <sup>(3)</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), WebSocket (RFC 6455, JSR 356), FastCGI</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Deprecated / <strong>End of Life December 2020</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">9.2</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2014-2018</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Eclipse</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.7 <sup>(3)</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 RFC2616, javax.websocket, SPDY v3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Deprecated / <strong>End of Life January 2018</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">9.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2013-2014</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Eclipse</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.7 <sup>(3)</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 RFC2616</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Deprecated / <strong>End of Life May 2014</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">9.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2013-2013</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Eclipse</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.7 <sup>(3)</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 RFC2616</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3.1-beta</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Deprecated / <strong>End of Life November 2013</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">8</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2009-2014</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Eclipse/Codehaus</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.6 <sup>(3)</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 RFC2616, WebSocket RFC 6455, SPDY v3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.2</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Deprecated / <strong>End of Life November 2014</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">7</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2008-2014</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Eclipse/Codehaus</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.5</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 RFC2616, WebSocket RFC 6455, SPDY v3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.5</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Deprecated / <strong>End of Life November 2014</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">6</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2006-2010</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Codehaus</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.4-1.5</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 RFC2616</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.5</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Deprecated / <strong>End of Life November 2010</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">5</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2003-2009</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Sourceforge</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.2-1.5</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 RFC2616</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.4</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Antique</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2001-2006</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Sourceforge</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.2, J2ME</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 RFC2616</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.2</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Ancient</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">3</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1999-2002</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Sourceforge</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.2</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.1 RFC2068</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.2</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Fossilized</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1998-2000</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Mortbay</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.0 RFC1945</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Legendary</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1995-1998</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Mortbay</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTTP/1.0 RFC1945</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Mythical</p></td>
</tr>
</tbody>
</table>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Due to Oracle&#8217;s ownership of the "Java" trademark, usage of the javax.* namespace has been restricted and the jakarta.* namespace <a href="https://www.eclipse.org/lists/jakartaee-platform-dev/msg00029.html">was adopted</a> by the Eclipse Foundation.</p>
</li>
<li>
<p>JPMS module support is optional</p>
</li>
<li>
<p>JDK9 and newer is not supported if using MultiRelease JAR Files, or Bytecode / Annotation scanning.</p>
</li>
</ol>
</div>
</div>
<div class="sect2">
<h3 id="jetty-javaee"><a class="anchor" href="#jetty-javaee"></a><a class="link" href="#jetty-javaee">Jetty and Java EE Web Profile</a></h3>
<div class="paragraph">
<p>Jetty implements aspects of the Java EE specification, primarily the Servlet Specification.
Recent releases of the Java EE platform have introduced a Web Profile, recognizing that many developers need only a subset of the many technologies under the Java EE umbrella.</p>
</div>
<div class="paragraph">
<p>While Jetty itself does not ship all of the Web Profile technologies, Jetty architecture is such that you can plug in third party implementations to produce a container customized to your exact needs.</p>
</div>
<div class="sect3">
<h4 id="jetty-javaee-7"><a class="anchor" href="#jetty-javaee-7"></a><a class="link" href="#jetty-javaee-7">Java EE 7 Web Profile</a></h4>
<div class="paragraph">
<p>In the forthcoming Java EE-7 specification, the Web Profile reflects updates in its component specifications and adds some new ones:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 15. JavaEE7 Web Profile</caption>
<colgroup>
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">JSR</th>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Included with jetty-9.1.x</th>
<th class="tableblock halign-left valign-top">Pluggable</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=340">JSR 340</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Servlet Specification API 3.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=344">JSR 344</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java Server Faces 2.2 (JSF)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes, <a href="https://javaserverfaces.java.net/">Mojarra</a> or <a href="http://myfaces.apache.org/">MyFaces</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=245">JSR 245</a> / <a href="http://jcp.org/en/jsr/detail?id=341">JSR 341</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java Server Pages 2.3/Java Expression Language 3.0 (JSP/EL)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=52">JSR 52</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java Standard Tag Library 1.2 (JSTL)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=45">JSR 45</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Debugging Support for Other Languages 1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes (via JSP)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes (via JSP)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=346">JSR 346</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Contexts and Dependency Injection for the JavaEE Platform 1.1 (Web Beans)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes, <a href="http://seamframework.org/Weld">Weld</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=330">JSR 330</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Dependency Injection for Java 1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes as part of a CDI implementation, <a href="http://seamframework.org/Weld">Weld</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=316">JSR 316</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Managed Beans 1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes, as part of another technology</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=345">JSR 345</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Enterprise JavaBeans 3.2 Lite</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=338">JSR 338</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java Persistence 2.1 (JPA)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes, eg <a href="http://www.hibernate.org/">Hibernate</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=250">JSR 250</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Common Annotations for the Java Platform 1.2</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Partially (for non-core Servlet Spec annotations)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=907">JSR 907</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java Transaction API 1.2 (JTA)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=349">JSR 349</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Bean Validation 1.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes as part of another technology eg JSF, or a stand-alone implementation such as <a href="http://www.hibernate.org/subprojects/validator/docs.html">Hiberate
Validator</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=339">JSR 339</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java API for RESTful Web Services 2.0 (JAX-RS)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=356">JSR 356</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java API for Websocket 1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=353">JSR 353</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java API for JSON Processing 1.0 (JSON-P)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes, eg JSON-P <a href="https://java.net/projects/jsonp/">reference implementation</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=318">JSR 318</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Interceptors 1.2</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes as part of a CDI implementation</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect3">
<h4 id="jetty-javaee-6"><a class="anchor" href="#jetty-javaee-6"></a><a class="link" href="#jetty-javaee-6">Jetty EE 6 Web Profile</a></h4>
<div class="paragraph">
<p>Here is the matrix of JSRs for Java EE 6 Web Profile, and how they relate to Jetty:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 16. Java EE 6 Web Profile</caption>
<colgroup>
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">JSR</th>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Included with jetty-9.0.x</th>
<th class="tableblock halign-left valign-top">Pluggable</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=315">JSR 315</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Servlet Specification API 3.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=314">JSR 314</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">JavaServer Faces 2.0 (JSF)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes, for example, <a href="https://javaserverfaces.java.net/">Mojarra</a> or <a href="http://myfaces.apache.org/">MyFaces</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=245">JSR 245</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">JavaServer Pages 2.2/Java Expression Language 2.2 (JSP/EL)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=52">JSR 52</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java Standard Tag Library 1.2 (JSTL)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=45">JSR 45</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Debugging Support for Other Languages 1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes (via JSP)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes (via JSP)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=299">JSR 299</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Contexts and Dependency Injection for the Java EE Platform 1.0 (Web Beans)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes, <a href="http://seamframework.org/Weld">Weld</a> or <a href="http://openwebbeans.apache.org/">OpenWebBeans</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=330">JSR 330</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Dependency Injection for Java 1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes as part of a CDI implementation, <a href="http://seamframework.org/Weld">Weld</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=316">JSR 316</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Managed Beans 1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes, as part of another technology.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=318">JSR 318</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Enterprise JavaBeans 3.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes, OpenEJB</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=317">JSR 317</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java Persistence 2.0 (JPA)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes, <a href="http://www.hibernate.org/">Hibernate</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=250">JSR 250</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Common Annotations for the Java Platform</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Partially (for non-core Servlet Spec annotations)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=907">JSR 907</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java Transaction API (JTA)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Implementations are pluggable, such as <a href="http://www.atomikos.com/">Atomikos</a>, <a href="http://jotm.ow2.org/">JOTM</a>, <a href="http://jencks.codehaus.org/Transaction+Manager">Jencks (Geronimo Transaction Manager)</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://jcp.org/en/jsr/detail?id=303">JSR 303</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Bean Validation 1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Yes as part of another technology (JSF), or a stand-alone implementation such as <a href="http://www.hibernate.org/subprojects/validator/docs.html">Hiberate
Validator</a></p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="sect2">
<h3 id="quickstart-jetty-coordinates"><a class="anchor" href="#quickstart-jetty-coordinates"></a><a class="link" href="#quickstart-jetty-coordinates">Finding Jetty in Maven</a></h3>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
It is important that only stable releases are used in production environments.
Versions that have been deprecated or are released as Milestones (M) or Release Candidates (RC) are not suitable for production as they may contain security flaws or incomplete/non-functioning feature sets.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect3">
<h4 id="_maven-coordinates-8"><a class="anchor" href="#_maven-coordinates-8"></a><a class="link" href="#_maven-coordinates-8">Maven Coordinates</a></h4>
<div class="paragraph">
<p>Jetty has existed in Maven Central almost since its inception, though the coordinates have changed over the years.
When Jetty was based at SourceForge and then The Codehaus it was located under the <code>groupId</code> of <code>org.mortbay.jetty</code>.
With Jetty 7 the project moved to the Eclipse foundation and to a new <code>groupId</code> at that time to reflect its new home.</p>
</div>
<div class="paragraph">
<p>The top level Project Object Model (POM) for the Jetty project is located under the following coordinates.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-project<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_changelogs-in-maven-central"><a class="anchor" href="#_changelogs-in-maven-central"></a><a class="link" href="#_changelogs-in-maven-central">Changelogs in Maven Central</a></h4>
<div class="paragraph">
<p>The changes between versions of Jetty are tracked in a file called VERSIONS.txt, which is under source control and is generated on release.
Those generated files are also uploaded into Maven Central during the release of the top level POM. You can find them as a classifier marked artifact.</p>
</div>
<div class="paragraph">
<p><a href="https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-project/" class="bare">https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-project/</a></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-project<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>${project.version}<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;classifier&gt;</span>version<span class="tag">&lt;/classifier&gt;</span>
<span class="tag">&lt;type&gt;</span>txt<span class="tag">&lt;/type&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="quick-start-getting-started"><a class="anchor" href="#quick-start-getting-started"></a><a class="link" href="#quick-start-getting-started">Using Jetty</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>You can use Jetty in many different ways ranging from embedding Jetty in applications, launching it from different build systems, from different JVM-based languages, or as a standalone distribution.
This guide covers the latter, a standalone distribution suitable for deploying web applications.</p>
</div>
<div class="sect2">
<h3 id="jetty-downloading"><a class="anchor" href="#jetty-downloading"></a><a class="link" href="#jetty-downloading">Downloading Jetty</a></h3>
<div class="sect3">
<h4 id="_downloading-the-jetty-distribution"><a class="anchor" href="#_downloading-the-jetty-distribution"></a><a class="link" href="#_downloading-the-jetty-distribution">Downloading the Jetty Distribution</a></h4>
<div class="paragraph">
<p>The standalone Jetty distribution is available for download from the Eclipse Foundation:</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
<p><strong>Jetty</strong>
<a href="https://www.eclipse.org/jetty/download.html" class="bare">https://www.eclipse.org/jetty/download.html</a></p>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>It is available in both zip and gzip formats; download the one most appropriate for your system.
When you download and unpack the binary, it is extracted into a directory called <code>jetty-home-VERSION.</code>
Put this directory in a convenient location.
The rest of the instructions in this documentation refer to this location as either <code>$JETTY_HOME</code> or as <code>$(jetty.home).</code></p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
It is important that <strong>only</strong> stable releases are used in production environments.
Versions that have been deprecated or are released as Milestones (M) or Release Candidates (RC) are <strong>not</strong> suitable for production as they may contain security flaws or incomplete/non-functioning feature sets.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect4">
<h5 id="distribution-content"><a class="anchor" href="#distribution-content"></a><a class="link" href="#distribution-content">Distribution Content</a></h5>
<div class="paragraph">
<p>A summary of the distribution&#8217;s contents follows.
The top-level directory contains:</p>
</div>
<table class="tableblock frame-all grid-all" style="width: 80%;">
<caption class="title">Table 17. Contents</caption>
<colgroup>
<col style="width: 40%;">
<col style="width: 60%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Location</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">license-eplv10-aslv20.html</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">License file for Jetty</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">README.txt</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Useful getting started information</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">VERSION.txt</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Release information</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">bin/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Utility shell scripts to help run Jetty on Unix systems</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">demo-base/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">A Jetty base directory to run a Jetty server with demonstration webapps</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">etc/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Directory for Jetty XML configuration files</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">lib/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">All the JAR files necessary to run Jetty</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">logs/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Directory for request logs</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">modules/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Directory of module definitions</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">notice.html</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">License information and exceptions</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">resources/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Directory containing additional resources for classpath, activated via configuration</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">start.ini</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">File containing the arguments that are added to the effective command line (modules, properties and XML configuration files)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">start.jar</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Jar that invokes Jetty (see also <a href="#quickstart-running-jetty">Running Jetty</a>)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">webapps/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Directory containing webapps that run under the default configuration of Jetty</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="sect3">
<h4 id="jetty-home-downloading"><a class="anchor" href="#jetty-home-downloading"></a><a class="link" href="#jetty-home-downloading">Downloading the Jetty-Home Distribution</a></h4>
<div class="paragraph">
<p>Jetty-Home is an alternate version of the distribution that contains only the necessary items to host a Jetty distribution.
It is intended for advanced users who are already familiar with Jetty and want to download a smaller distribution package.
Jetty-Home can be downloaded from the Maven Central repository:</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
<p><strong>Jetty-Home</strong>
<a href="https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/" class="bare">https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/</a></p>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>Like the main Jetty distribution, Jetty-Home is available in both zip and gzip formats; download the one most appropriate for your system.
Notice that there are a number of other files with extensions of .sha or .md5 which are checksum files.
When you download and unpack the binary, it is extracted into a directory called <code>jetty-home-VERSION.</code>
Put this directory in a convenient location.</p>
</div>
<div class="sect4">
<h5 id="jetty-home-distribution-content"><a class="anchor" href="#jetty-home-distribution-content"></a><a class="link" href="#jetty-home-distribution-content">Distribution Content</a></h5>
<div class="paragraph">
<p>A summary of the Jetty-Home&#8217;s distribution contents follows.
The top-level directory contains:</p>
</div>
<table class="tableblock frame-all grid-all" style="width: 80%;">
<caption class="title">Table 18. Contents</caption>
<colgroup>
<col style="width: 40%;">
<col style="width: 60%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Location</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">license-eplv10-aslv20.html</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">License file for Jetty</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">VERSION.txt</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Release information</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">etc/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Directory for Jetty XML configuration files</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">lib/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">All the JAR files necessary to run Jetty</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">modules/</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Directory of module definitions</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">notice.html</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">License information and exceptions</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">start.jar</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Jar that invokes Jetty (see also <a href="#quickstart-running-jetty">Running Jetty</a>)</p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="sect2">
<h3 id="quickstart-running-jetty"><a class="anchor" href="#quickstart-running-jetty"></a><a class="link" href="#quickstart-running-jetty">Running Jetty</a></h3>
<div class="paragraph">
<p>Once you have a copy of the Jetty distribution downloaded, extract the <code>zip</code> or <code>tar.gz</code> file to a location where you have read and write access.
Jetty has no GUI (Graphical User Interface), so running the server and performing many configuration options is done from the command line.</p>
</div>
<div class="paragraph">
<p>Once you have access to your system&#8217;s command line, navigate to the directory where you unpacked your copy of the Jetty distribution.
To start Jetty on the default port of 8080, run the following command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ java -jar start.jar
2017-09-20 15:45:11.986:INFO::main: Logging initialized @683ms to org.eclipse.jetty.util.log.StdErrLog
2017-09-20 15:45:12.197:WARN:oejs.HomeBaseWarning:main: This instance of Jetty is not running from a separate {jetty.base} directory, this is not recommended. See documentation at https://www.eclipse.org/jetty/documentation/current/startup.html
2017-09-20 15:45:12.243:INFO:oejs.Server:main: 10.0.10
2017-09-20 15:45:12.266:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///installs/repository/jetty/webapps/] at interval 1
2017-09-20 15:45:12.298:INFO:oejs.AbstractConnector:main: Started ServerConnector@39c0f4a{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2017-09-20 15:45:12.298:INFO:oejs.Server:main: Started @995ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can point a browser at this server at <a href="http://localhost:8080" class="bare">http://localhost:8080</a>.
However, as there are no webapps deployed in the <code>$JETTY_HOME</code> directory, you will see a 404 error page served by Jetty.
To stop the server, press <code>CTRL</code> + <code>c</code> or <code>CTRL</code> + <code>z</code> in your terminal.</p>
</div>
<div class="paragraph">
<p><strong>Note</strong> the <code>HomeBaseWarning</code> - it is <strong>not</strong> recommended to run Jetty from the <code>$JETTY_HOME</code> directory.
Instead, see how to <a href="#creating-jetty-base">create a Jetty Base</a> below.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
You will see examples throughout the documentation referencing <code>$JETTY_HOME</code> and <code>$JETTY_BASE</code> as well as <code>{jetty.home}</code> and <code>{jetty.base}</code>.
These terms are used to refer to the location of your Jetty installation directories.
Many users find it helpful to define <code>$JETTY_HOME</code> as an environment variable that maps to their Jetty distribution directory.
More information can be found in our Administration section on <a href="#startup-base-and-home">managing Jetty Home and Jetty Base.</a>
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect3">
<h4 id="demo-webapps-base"><a class="anchor" href="#demo-webapps-base"></a><a class="link" href="#demo-webapps-base">Demo Base</a></h4>
<div class="paragraph">
<p>Within the standard Jetty distribution there is the <code>demo-base</code> directory.
This is a fully-functioning Jetty Base (more on that later) complete with numerous web applications demonstrating different Jetty functionality.
Additionally, the <code>demo-base</code> demonstrates the recommended way to run a Jetty base in a directory separate from <code>$JETTY_HOME</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ cd demo-base/
[my-base]$ java -jar /path/to/jetty-home/start.jar
2017-09-20 16:23:03.563:INFO::main: Logging initialized @429ms to org.eclipse.jetty.util.log.StdErrLog
2017-09-20 16:23:03.802:WARN::main: demo test-realm is deployed. DO NOT USE IN PRODUCTION!
2017-09-20 16:23:03.804:INFO:oejs.Server:main: 10.0.10
2017-09-20 16:23:03.819:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///installs/repository/jetty/demo-base/webapps/] at interval 1
2017-09-20 16:23:04.098:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=102ms
2017-09-20 16:23:04.103:WARN::main: async-rest webapp is deployed. DO NOT USE IN PRODUCTION!
2017-09-20 16:23:04.267:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2017-09-20 16:23:04.267:INFO:oejs.session:main: No SessionScavenger set, using defaults
2017-09-20 16:23:04.268:INFO:oejs.session:main: Scavenging every 660000ms
2017-09-20 16:23:04.306:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@371a67ec{/async-rest,[file:///private/var/folders/h6/yb_lbnnn11g0y1jjlvqg631h0000gn/T/jetty-0.0.0.0-8080-async-rest.war-_async-rest-any-5319296087878801290.dir/webapp/, jar:file:///private/var/folders/h6/yb_lbnnn11g0y1jjlvqg631h0000gn/T/jetty-0.0.0.0-8080-async-rest.war-_async-rest-any-5319296087878801290.dir/webapp/WEB-INF/lib/example-async-rest-jar-10.0.10.jar!/META-INF/resources],AVAILABLE}{/async-rest.war}
2017-09-20 16:23:04.429:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=53ms
2017-09-20 16:23:04.432:WARN::main: test webapp is deployed. DO NOT USE IN PRODUCTION!
2017-09-20 16:23:04.511:INFO:oejsh.ManagedAttributeListener:main: update PushFilter null-&gt;org.eclipse.jetty.servlets.PushCacheFilter@2362f559 on o.e.j.w.WebAppContext@35e2d654{/test,file:///private/var/folders/h6/yb_lbnnn11g0y1jjlvqg631h0000gn/T/jetty-0.0.0.0-8080-test.war-_test-any-6279588879522983394.dir/webapp/,STARTING}{/test.war}
2017-09-20 16:23:04.516:INFO:oejsh.ManagedAttributeListener:main: update QoSFilter null-&gt;org.eclipse.jetty.servlets.QoSFilter@7770f470 on o.e.j.w.WebAppContext@35e2d654{/test,file:///private/var/folders/h6/yb_lbnnn11g0y1jjlvqg631h0000gn/T/jetty-0.0.0.0-8080-test.war-_test-any-6279588879522983394.dir/webapp/,STARTING}{/test.war}
2017-09-20 16:23:04.519:WARN:oeju.DeprecationWarning:main: Using @Deprecated Class org.eclipse.jetty.servlets.MultiPartFilter
2017-09-20 16:23:04.549:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@35e2d654{/test,file:///private/var/folders/h6/yb_lbnnn11g0y1jjlvqg631h0000gn/T/jetty-0.0.0.0-8080-test.war-_test-any-6279588879522983394.dir/webapp/,AVAILABLE}{/test.war}
2017-09-20 16:23:04.646:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=12ms
2017-09-20 16:23:04.649:WARN::main: test-jndi webapp is deployed. DO NOT USE IN PRODUCTION!
2017-09-20 16:23:04.697:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@561b6512{/test-jndi,file:///private/var/folders/h6/yb_lbnnn11g0y1jjlvqg631h0000gn/T/jetty-0.0.0.0-8080-test-jndi.war-_test-jndi-any-6023636263414992288.dir/webapp/,AVAILABLE}{/test-jndi.war}
2017-09-20 16:23:04.770:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=40ms
2017-09-20 16:23:05.036:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@2beee7ff{/proxy,file:///private/var/folders/h6/yb_lbnnn11g0y1jjlvqg631h0000gn/T/jetty-0.0.0.0-8080-javadoc-proxy.war-_javadoc-proxy-any-2758874759195597975.dir/webapp/,AVAILABLE}{/javadoc-proxy.war}
2017-09-20 16:23:05.072:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=16ms
2017-09-20 16:23:05.074:WARN::main: test-jaas webapp is deployed. DO NOT USE IN PRODUCTION!
2017-09-20 16:23:05.098:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@506ae4d4{/test-jaas,file:///private/var/folders/h6/yb_lbnnn11g0y1jjlvqg631h0000gn/T/jetty-0.0.0.0-8080-test-jaas.war-_test-jaas-any-8067423971450448377.dir/webapp/,AVAILABLE}{/test-jaas.war}
2017-09-20 16:23:05.182:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=37ms
2017-09-20 16:23:05.184:WARN::main: test-spec webapp is deployed. DO NOT USE IN PRODUCTION!
2017-09-20 16:23:05.243:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@45099dd3{/test-spec,[file:///private/var/folders/h6/yb_lbnnn11g0y1jjlvqg631h0000gn/T/jetty-0.0.0.0-8080-test-spec.war-_test-spec-any-1205866915335004234.dir/webapp/, jar:file:///private/var/folders/h6/yb_lbnnn11g0y1jjlvqg631h0000gn/T/jetty-0.0.0.0-8080-test-spec.war-_test-spec-any-1205866915335004234.dir/webapp/WEB-INF/lib/test-web-fragment-10.0.10.jar!/META-INF/resources],AVAILABLE}{/test-spec.war}
2017-09-20 16:23:05.247:INFO:oejsh.ContextHandler:main: Started o.e.j.s.h.MovedContextHandler@3e08ff24{/oldContextPath,null,AVAILABLE}
2017-09-20 16:23:05.274:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=18ms
2017-09-20 16:23:05.296:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@5ddeb7cb{/,file:///installs/repository/jetty/demo-base/webapps/ROOT/,AVAILABLE}{/ROOT}
2017-09-20 16:23:05.326:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=21ms
2017-09-20 16:23:05.352:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@6b695b06{/doc,file:///installs/repository/jetty/demo-base/webapps/doc/,AVAILABLE}{/doc}
2017-09-20 16:23:05.370:INFO:oejs.AbstractConnector:main: Started ServerConnector@28cda624{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2017-09-20 16:23:05.380:INFO:oejus.SslContextFactory:main: x509=X509@126253fd(jetty,h=[jetty.eclipse.org],w=[]) for SslContextFactory@57db2b13(file:///installs/repository/jetty/demo-base/etc/keystore,file:///installs/repository/jetty/demo-base/etc/keystore)
2017-09-20 16:23:05.381:INFO:oejus.SslContextFactory:main: x509=X509@475c9c31(mykey,h=[],w=[]) for SslContextFactory@57db2b13(file:///installs/repository/jetty/demo-base/etc/keystore,ffile:///installs/repository/jetty/demo-base/etc/keystore)
2017-09-20 16:23:05.523:INFO:oejs.AbstractConnector:main: Started ServerConnector@53f3bdbd{SSL,[ssl, http/1.1]}{0.0.0.0:8443}
2017-09-20 16:23:05.524:INFO:oejs.Server:main: Started @2390ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can visit this demo server by pointing a browser at <a href="http://localhost:8080" class="bare">http://localhost:8080</a>, which will now show a welcome page and several demo/test web applications.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
The demonstration web applications are not necessarily secure and should <strong>not</strong> be deployed in production web servers.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>You can see the configuration of the <code>demo-base</code> by using the following commands:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; cd $JETTY_HOME/demo-base/
&gt; java -jar $JETTY_HOME/start.jar --list-modules
...
&gt; java -jar $JETTY_HOME/start.jar --list-config
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>--list-modules</code> command will return a complete list of available and enabled modules for the server.
It will also display the location of the modules, how and in what order they are implemented, dependent modules, and associated jar files.</p>
</div>
<div class="paragraph">
<p>The <code>--list-config</code> command displays a trove of information about the server including the Java and Jetty environments, the configuration order, any JVM arguments or System Properties set, general server properties, a full listing of the Jetty server class path, and active Jetty XML files.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="quickstart-common-config"><a class="anchor" href="#quickstart-common-config"></a><a class="link" href="#quickstart-common-config">Common Jetty Configuration</a></h3>
<div class="sect3">
<h4 id="creating-jetty-base"><a class="anchor" href="#creating-jetty-base"></a><a class="link" href="#creating-jetty-base">Creating a new Jetty Base</a></h4>
<div class="paragraph">
<p>The <code>demo-base</code> directory described earlier is an example of the <a href="#startup-base-and-home"><code>jetty.base</code></a> mechanism.
A Jetty base directory allows the configuration and web applications of a server instance to be stored separately from the Jetty distribution, so that upgrades can be done with minimal disruption.
Jetty&#8217;s default configuration is based on two properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.home</dt>
<dd>
<p>The property that defines the location of the Jetty distribution, its libs, default modules and default XML files (typically start.jar, lib, etc).</p>
</dd>
<dt class="hdlist1">jetty.base</dt>
<dd>
<p>The property that defines the location of a specific implementation of a Jetty server, its configuration, logs and web applications (typically start.d/*.ini files, logs and webapps).</p>
</dd>
</dl>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
Your Jetty Home directory should be treated as a standard of truth and remain unmodified or changed.
Changes or additions to your configuration should take place in the Jetty Base directory.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>The <code>jetty.home</code> and <code>jetty.base</code> properties may be explicitly set on the command line, or they can be inferred from the environment if used with commands like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; cd $JETTY_BASE
&gt; java -jar $JETTY_HOME/start.jar</code></pre>
</div>
</div>
<div class="paragraph">
<p>The following commands create a new base directory, enables both the HTTP connector and the web application deployer modules, and copies a demo webapp to be deployed:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; JETTY_BASE=/tmp/mybase
&gt; mkdir $JETTY_BASE
&gt; cd $JETTY_BASE
&gt; java -jar $JETTY_HOME/start.jar
WARNING: Nothing to start, exiting ...
Usage: java -jar start.jar [options] [properties] [configs]
java -jar start.jar --help # for more information
&gt; java -jar $JETTY_HOME/start.jar --create-startd
INFO : Base directory was modified
&gt; java -jar $JETTY_HOME/start.jar --add-to-start=http,deploy
INFO: server initialised (transitively) in ${jetty.base}/start.d/server.ini
INFO: http initialised in ${jetty.base}/start.d/http.ini
INFO: security initialised (transitively) in ${jetty.base}/start.d/security.ini
INFO: servlet initialised (transitively) in ${jetty.base}/start.d/servlet.ini
INFO: webapp initialised (transitively) in ${jetty.base}/start.d/webapp.ini
INFO: deploy initialised in ${jetty.base}/start.d/deploy.ini
MKDIR: ${jetty.base}/webapps
INFO: Base directory was modified
&gt; cp $JETTY_HOME/demo-base/webapps/async-rest.war webapps/ROOT.war
&gt; java -jar $JETTY_HOME/start.jar
2015-06-04 11:10:16.286:INFO::main: Logging initialized @274ms
2015-06-04 11:10:16.440:INFO:oejs.Server:main: jetty-9.3.0.v20150601
2015-06-04 11:10:16.460:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///tmp/mybase/webapps/] at interval 1
2015-06-04 11:10:16.581:WARN::main: async-rest webapp is deployed. DO NOT USE IN PRODUCTION!
2015-06-04 11:10:16.589:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2015-06-04 11:10:16.628:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@1a407d53{/,[file:///tmp/jetty-0.0.0.0-8080-ROOT.war-_-any-4510228025526425427.dir/webapp/, jar:file:///tmp/jetty-0.0.0.0-8080-ROOT.war-_-any-4510228025526425427.dir/webapp/WEB-INF/lib/example-async-rest-jar-10.0.10.jar!/META-INF/resources],AVAILABLE}{/ROOT.war}
2015-06-04 11:10:16.645:INFO:oejs.ServerConnector:main: Started ServerConnector@3abbfa04{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2015-06-04 11:10:16.646:INFO:oejs.Server:main: Started @634ms</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="quickstart-changing-jetty-port"><a class="anchor" href="#quickstart-changing-jetty-port"></a><a class="link" href="#quickstart-changing-jetty-port">Changing the Jetty Port</a></h4>
<div class="paragraph">
<p>You can configure Jetty to run on a different port by setting the <code>jetty.http.port</code> property on the command line:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; cd $JETTY_BASE
&gt; java -jar $JETTY_HOME/start.jar jetty.http.port=8081
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>When the server starts, it will now run on port <code>8081</code>.
It is important to note that setting properties on the command line will only take affect for that instance of the server.
To change the configuration so that the server will always start on the desired port, you will need to edit the <code>start.d/http.ini</code></p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The configuration by properties works via the following chain:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The <code>start.d/http.ini</code> file is part of the effective command line and contains the <code>--module=http</code> argument which activates the http module.</p>
</li>
<li>
<p>The <code>modules/http.mod</code> file defines the http module which specifies the <code>etc/jetty-http.xml</code> configuration file and the template ini properties it uses.</p>
</li>
<li>
<p>The <code>jetty.http.port</code> property is used by the Property XML element in <code>etc/jetty.http.xml</code> to inject the <code>ServerConnector</code> instance with the port.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>For more information see the <a href="#quick-start-configure">Quickstart Configuration Guide</a> and <a href="#configuring-connectors">Configuring Connectors</a>.</p>
</div>
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="quickstart-starting-https"><a class="anchor" href="#quickstart-starting-https"></a><a class="link" href="#quickstart-starting-https">Adding SSL for HTTPS &amp; HTTP2</a></h4>
<div class="paragraph">
<p>Building on the example above, we can activate additional modules to add support HTTPS and HTTP2 for the server.
To add HTTPS and HTTP2 connectors to a Jetty configuration, the modules can be activated by the following command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar $JETTY_HOME/start.jar --add-to-start=https,http2
ALERT: There are enabled module(s) with licenses.
The following 1 module(s):
+ contains software not provided by the Eclipse Foundation!
+ contains software not covered by the Eclipse Public License!
+ has not been audited for compliance with its license
Module: alpn-impl/alpn-8
+ ALPN is a hosted at github under the GPL v2 with ClassPath Exception.
+ ALPN replaces/modifies OpenJDK classes in the sun.security.ssl package.
+ http://github.com/jetty-project/jetty-alpn
+ http://openjdk.java.net/legal/gplv2+ce.html
Proceed (y/N)? y
INFO : alpn-impl/alpn-1.8.0_92 dynamic dependency of alpn-impl/alpn-8
INFO : alpn transitively enabled, ini template available with --add-to-start=alpn
INFO : alpn-impl/alpn-8 dynamic dependency of alpn
INFO : http2 initialized in ${jetty.base}/start.d/http2.ini
INFO : https initialized in ${jetty.base}/start.d/https.ini
INFO : ssl transitively enabled, ini template available with --add-to-start=ssl
MKDIR : ${jetty.base}/lib/alpn
DOWNLD: https://repo1.maven.org/maven2/org/mortbay/jetty/alpn/alpn-boot/8.1.8.v20160420/alpn-boot-8.1.8.v20160420.jar to ${jetty.base}/lib/alpn/alpn-boot-8.1.8.v20160420.jar
MKDIR : ${jetty.base}/etc
COPY : ${jetty.home}/modules/ssl/keystore to ${jetty.base}/etc/keystore
INFO : Base directory was modified
&gt; java -jar $JETTY_HOME/start.jar
[...]
2017-05-22 12:48:23.271:INFO:oejs.AbstractConnector:main: Started ServerConnector@134d0064{SSL,[ssl, alpn, h2, http/1.1]}{0.0.0.0:8443}
[...]</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>--add-to-start</code> command sets up the effective command line in the ini files to run an ssl connection that supports the HTTPS and HTTP2 protocols as follows:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>transitively enabled the <code>ssl</code> module that configures an SSL connector (eg port, keystore etc.) by adding <code>etc/jetty-ssl.xml</code> and <code>etc/jetty-ssl-context.xml</code> to the effective command line.</p>
</li>
<li>
<p>transitively enabled the <code>alpn</code> module that configures protocol negotiation on the SSL connector by adding <code>etc/jetty-alpn.xml</code> to the effective command line.</p>
</li>
<li>
<p>creates <code>start.d/https.ini</code> that configures the HTTPS protocol on the SSL connector by adding <code>etc/jetty-https.xml</code> to the effective command line.</p>
</li>
<li>
<p>creates <code>start.d/http2.ini</code> that configures the HTTP/2 protocol on the SSL connector by adding <code>etc/jetty-http2.xml</code> to the effective command line.</p>
</li>
<li>
<p>checks for the existence of a <code>etc/keystore</code> file and if not present, downloads a demonstration keystore file.</p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="quickstart-changing-https-port"><a class="anchor" href="#quickstart-changing-https-port"></a><a class="link" href="#quickstart-changing-https-port">Changing the Jetty HTTPS Port</a></h5>
<div class="paragraph">
<p>You can configure the SSL connector to run on a different port by setting the <code>jetty.ssl.port</code> property on the command line:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; cd $JETTY_BASE
&gt; java -jar $JETTY_HOME/start.jar jetty.ssl.port=8444</code></pre>
</div>
</div>
<div class="paragraph">
<p>Alternatively, property values can be added to the effective command line built from the <code>start.ini</code> file or <code>start.d/*.ini</code> files, depending on your set up.
Please see the section on <a href="#start-vs-startd">Start.ini vs. Start.d</a> for more information.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_more-start-jar-options"><a class="anchor" href="#_more-start-jar-options"></a><a class="link" href="#_more-start-jar-options">More start.jar Options</a></h4>
<div class="paragraph">
<p>The job of the <code>start.jar</code> is to interpret the command line, <code>start.ini</code> and <code>start.d</code> directory (and associated .ini files) to build a Java classpath and list of properties and configuration files to pass to the main class of the Jetty XML configuration mechanism.
The <code>start.jar</code> mechanism has many options which are documented in the <a href="#startup">Starting Jetty</a> administration section and you can see them in summary by using the command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar $JETTY_HOME/start.jar --help</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="quick-start-configure"><a class="anchor" href="#quick-start-configure"></a><a class="link" href="#quick-start-configure">An Introduction to Jetty Configuration</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="quickstart-config-what"><a class="anchor" href="#quickstart-config-what"></a><a class="link" href="#quickstart-config-what">What to Configure in Jetty</a></h3>
<div class="paragraph">
<p>This section gives an overview of the components of Jetty you typically configure using the mechanisms outlined in the previous section.
<a href="#basic-architecture">[basic-architecture]</a> describes the structure of a Jetty server, which is good background reading to understand configuration, and is vital if you want to change the structure of the server as set up by the default configurations in the Jetty distribution.
However, for most purposes, configuration is a matter of identifying the correct configuration file and modifying existing configuration values.</p>
</div>
<div class="sect3">
<h4 id="intro-jetty-configuration-server"><a class="anchor" href="#intro-jetty-configuration-server"></a><a class="link" href="#intro-jetty-configuration-server">Configuring the Server</a></h4>
<div class="paragraph">
<p>The Server instance is the central coordination object of a Jetty server; it provides services and life cycle management for all other Jetty server components.
In the standard Jetty distribution, the core server configuration is in <code>etc/jetty.xml</code> file, but you can mix in other server configurations which can include:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">ThreadPool</dt>
<dd>
<p>The Server instance provides a ThreadPool instance that is the default Executor service other Jetty server components use.
The prime configuration of the thread pool is the maximum and minimum size and is set in <code>start.ini</code> or <code>start.d/server.ini</code>.</p>
</dd>
<dt class="hdlist1">Handlers</dt>
<dd>
<p>A Jetty server can have only a single Handler instance to handle incoming HTTP requests.
However a handler may be a container or wrapper of other handlers forming a tree of handlers that typically
handle a request as a collaboration between the handlers from a branch of the tree from root to leaf.
The default handler tree set up in the <code>etc/jetty.xml</code> file is a Handler Collection containing a Context Handler Collection and the Default Handler.
The Context Handler Collection selects the next handler by context path and is where deployed Context Handler and Web Application Contexts are added to the handler tree.
The Default Handler handles any requests not already handled and generates the standard 404 page.
Other configuration files may add handlers to this tree (for example, <code>jetty-rewrite.xml</code>, <code>jetty-requestlog.xml</code>) or configure components to hot deploy handlers (for example, <code>jetty-deploy.xml</code>).</p>
</dd>
<dt class="hdlist1">Server Attributes</dt>
<dd>
<p>The server holds a generic attribute map of strings to objects so that other Jetty components can associate named objects with the server, and if the value objects implement the LifeCycle interface, they are started and stopped with the server.
Typically server attributes hold server-wide default values.</p>
</dd>
<dt class="hdlist1">Server fields</dt>
<dd>
<p>The server also has some specific configuration fields that you set in <code>start.ini</code> or <code>start.d/server.ini</code> for controlling, among other things, the sending of dates and versions in HTTP responses.</p>
</dd>
<dt class="hdlist1">Connectors</dt>
<dd>
<p>The server holds a collection of connectors that receive connections for HTTP and the other protocols that Jetty supports.
The next section, <a href="#intro-jetty-configuration-connectors">Configuring Connectors</a> describes configuration of the connectors themselves.
For the server you can either set the collection of all connectors or add/remove individual connectors.</p>
</dd>
<dt class="hdlist1">Services</dt>
<dd>
<p>The server can hold additional service objects, sometimes as attributes, but often as aggregated LifeCycle beans.
Examples of services are Login Services and DataSources, which you configure at the server level and then inject into the web applications that use them.</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="intro-jetty-configuration-connectors"><a class="anchor" href="#intro-jetty-configuration-connectors"></a><a class="link" href="#intro-jetty-configuration-connectors">Configuring Connectors</a></h4>
<div class="paragraph">
<p>A Jetty Server Connector is a network end point that accepts connections for one or more protocols which produce requests and/or messages for the Jetty server.
In the standard Jetty server distribution, several provided configuration files add connectors to the server for various protocols and combinations of protocols: <code>http.ini</code>, <code>https.ini</code> and <code>jetty-http2.xml</code>.
The configuration needed for connectors is typically:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Port</dt>
<dd>
<p>The TCP/IP port on which the connector listens for connections is set using the the XML Property element which looks up the <code>jetty.http.port</code> (or <code>jetty.ssl.port</code>) property, and if not found defaults to 8080 (or 8443 for TLS).</p>
</dd>
<dt class="hdlist1">Host</dt>
<dd>
<p>You can configure a host either as a host name or IP address to identify a specific network interface on which to listen.
If not set, or set to the value of 0.0.0.0, the connector listens on all local interfaces.
The XML Property element is used to look up the host value from the <code>jetty.host</code> property.</p>
</dd>
<dt class="hdlist1">Idle Timeout</dt>
<dd>
<p>The time in milliseconds that a connection can be idle before the connector takes action to close the connection.</p>
</dd>
<dt class="hdlist1">HTTP Configuration</dt>
<dd>
<p>Connector types that accept HTTP semantics (including HTTP, HTTPS and HTTP2) are configured with a <code>HttpConfiguration</code> instance that contains common HTTP configuration that is independent of the specific wire protocol used.
Because these values are often common to multiple connector types, the standard Jetty Server distribution creates a single <code>HttpConfiguration</code> in the <code>jetty.xml</code> file which is used via the XML Ref element in the specific connector files.</p>
</dd>
<dt class="hdlist1">SSL Context Factory</dt>
<dd>
<p>The TLS connector types (HTTPS and HTTP2) configure an SSL Context Factory with the location of the server keystore and truststore for obtaining server certificates.</p>
</dd>
</dl>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Virtual hosts are not configured on connectors. You must configure individual contexts with the virtual hosts to which they respond.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Prior to Jetty 9, the type of the connector reflected both the protocol supported (HTTP, HTTPS, AJP, SPDY), and the nature of the implementation (NIO or BIO).
From Jetty 9 onwards there is only one prime Connector type (<code>ServerConnector</code>), which is NIO based and uses Connection Factories to handle one or more protocols.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="intro-jetty-configuration-contexts"><a class="anchor" href="#intro-jetty-configuration-contexts"></a><a class="link" href="#intro-jetty-configuration-contexts">Configuring Contexts</a></h4>
<div class="paragraph">
<p>A Jetty context is a handler that groups other handlers under a context path together with associated resources and is roughly equivalent to the standard ServletContext API.
A context may contain either standard Jetty handlers or a custom application handler.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The servlet specification defines a web application.
In Jetty a standard web application is a specialized context that uses a standard layout and <code>WEB-INF/web.xml</code> to instantiate and configure classpath, resource base and handlers for sessions, security, and servlets, plus servlets for JSPs and static content.
Standard web applications often need little or no additional configuration, but you can also use the techniques for arbitrary contexts to refine or modify the configuration of standard web applications.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>Configuration values that are common to all contexts are:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">contextPath</dt>
<dd>
<p>The contextPath is a URL prefix that identifies which context a HTTP request is destined for.
For example, if a context has a context path <code>/foo</code>, it handles requests to <code>/foo</code>, <code>/foo/index.html</code>,
<code>/foo/bar/</code>, and <code>/foo/bar/image.png</code> but it does not handle requests like <code>/</code>, <code>/other/</code>, or <code>/favicon.ico</code>.
A context with a context path of / is called the root context.</p>
<div class="paragraph">
<p>The context path can be set by default from the deployer (which uses the filename as the basis for the context path); or in code; or it can be set by a Jetty IoC XML that is either applied by the deployer or found in the <code>WEB-INF/jetty-web.xml</code> file of a standard web app context.</p>
</div>
</dd>
<dt class="hdlist1">virtualHost</dt>
<dd>
<p>A context may optionally have one or more virtual hosts set.
Unlike the host set on a connector (which selects the network interface on which to listen), a virtual host does not set any network parameters.
Instead a virtual host represents an alias assigned by a name service to an IP address, which may have many aliases.
To determine which virtual host a request is intended for, the HTTP client (browser) includes in the request the name used to look up the network address.
A context with a virtual host set only handles requests that have a matching virtual host in their request headers.</p>
</dd>
<dt class="hdlist1">classPath</dt>
<dd>
<p>A context may optionally have a classpath, so that any thread that executes a handler within the context has a thread context classloader set with the classpath.
A standard web application has the classpath initialized by the <code>WEB-INF/lib</code> and <code>WEB-INF/classes</code> directory and
has additional rules about delegating classloading to the parent classloader.
All contexts may have additional classpath entries added.</p>
</dd>
<dt class="hdlist1">attributes</dt>
<dd>
<p>Attributes are arbitrary named objects that are associated with a context and are frequently used to pass entities between a web application and its container.
For example the attribute <code>javax.servlet.context.tempdir</code> is used to pass the File instance that represents the assigned temporary directory for a web application.</p>
</dd>
<dt class="hdlist1">resourceBase</dt>
<dd>
<p>The resource base is a directory (or collection of directories or URL) that contains the static resources for the context.
These can be images and HTML files ready to serve or JSP source files ready to be compiled.
In traditional web servers this value is often called the docroot.</p>
</dd>
</dl>
</div>
<div class="sect4">
<h5 id="_context-configuration-by-api"><a class="anchor" href="#_context-configuration-by-api"></a><a class="link" href="#_context-configuration-by-api">Context Configuration by API</a></h5>
<div class="paragraph">
<p>In an embedded server, you configure contexts by directly calling the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ContextHandler.html">ContextHandler</a> API as in the following example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in gettingstarted/configuring/what-to-configure.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneContext.java<span class="type">[]</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_context-configuration-by-ioc-xml"><a class="anchor" href="#_context-configuration-by-ioc-xml"></a><a class="link" href="#_context-configuration-by-ioc-xml">Context Configuration by IoC XML</a></h5>
<div class="paragraph">
<p>You can create and configure a context entirely by IoC XML (either Jetty&#8217;s or Spring).
The deployer discovers and hot deploys context IoC descriptors like the following which creates a context to serve the Javadoc from the Jetty distribution:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="comment">&lt;!--
Configure a custom context for serving javadoc as static resources
--&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.handler.ContextHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/javadoc<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">resourceBase</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/javadoc/<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">handler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.handler.ResourceHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">welcomeFiles</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Item&gt;</span>index.html<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">cacheControl</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>max-age=3600,public<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="intro-jetty-configuration-webapps"><a class="anchor" href="#intro-jetty-configuration-webapps"></a><a class="link" href="#intro-jetty-configuration-webapps">Configuring Web Applications</a></h5>
<div class="paragraph">
<p>The servlet specification defines a web application, which when packaged as a zip is called WAR file (Web application ARchive).
Jetty implements both WAR files and unpacked web applications as a specialized context that is configured by means of:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A standard layout which sets the location of the resourceBase (the root of the WAR) and initializes the classpath from jars found in <code>WEB-INF/lib</code> and classes found in <code>WEB-INF/classes</code>.</p>
</li>
<li>
<p>The standard <code>WEB-INF/web.xml</code> deployment descriptor which is parsed to define and configure init parameters, filters, servlets, listeners, security constraints, welcome files and resources to be injected.</p>
</li>
<li>
<p>A default <code>web.xml</code> format deployment descriptor provided either by Jetty or in configuration configures the JSP servlet and the default servlet for handling static content.
The standard <code>web.xml</code> may override the default <code>web.xml</code>.</p>
</li>
<li>
<p>Annotations discovered on classes in Jars contained in <code>WEB-INF/lib</code> can declare additional filters, servlets and listeners.</p>
</li>
<li>
<p>Standard deployment descriptor fragments discovered in Jars contained in <code>WEB-INF/lib</code> can declare additional init parameters, filters, servlets, listeners, security constraints, welcome files and resources to be injected.</p>
</li>
<li>
<p>An optional <code>WEB-INF/jetty-web.xml</code> file may contain Jetty IoC configuration to configure the Jetty specific APIs of the context and handlers.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Because these configuration mechanisms are contained within the WAR file (or unpacked web application), typically a web application contains much of its own configuration and deploying a WAR is often just a matter of dropping the WAR file in to the webapps directory that is scanned by the <a href="#quickstart-config-deployer">Jetty deployer</a>.</p>
</div>
<div class="paragraph">
<p>If you need to configure something within a web application, often you do so by unpacking the WAR file and editing the <code>web.xml</code> and other configuration files.
However, both the servlet standard and some Jetty features allow for other configuration to be applied to a web application externally from the WAR:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Configured data sources and security realms in the server can be injected into a web application either explicitly or by name matching.</p>
</li>
<li>
<p>Jetty allows one or more override deployment descriptors, in <code>web.xml</code> format, to be set on a context (via code or IoC XML) to amend the configuration set by the default and standard <code>web.xml</code>.</p>
</li>
<li>
<p>The normal Jetty Java API may be called by code or IoC XML to amend the configuration of a web application.</p>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="_setting-the-context-path"><a class="anchor" href="#_setting-the-context-path"></a><a class="link" href="#_setting-the-context-path">Setting the Context Path</a></h5>
<div class="paragraph">
<p>The web application standard provides no configuration mechanism for a web application or WAR file to set its own <code>contextPath</code>.
By default the deployer uses conventions to set the context path:
If you deploy a WAR file called <code>foobar.WAR</code>, the context path is <code>/foobar</code>; if you deploy a WAR file called <code>ROOT.WAR</code> the context path is <code>/</code>.</p>
</div>
<div class="paragraph">
<p>However, it is often desirable to explicitly set the context path so that information (for example, version numbers) may be included in the filename of the WAR.
Jetty allows the context Path of a WAR file to be set internally (by the WAR itself) or externally (by the deployer of the WAR).</p>
</div>
<div class="paragraph">
<p>To set the contextPath from within the WAR file, you can include a <code>WEB-INF/jetty-web.xml</code> file which contains IoC XML to set the context path:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/contextpath<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Alternately, you can configure the classpath externally without the need to modify the WAR file itself.
Instead of allowing the WAR file to be discovered by the deployer, an IoC XML file may be deployed that both sets the context path and declares the WAR file that it applies to:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/webapps/test.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/test<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>An example of setting the context path is included with the Jetty distribution in <code>$JETTY_HOME/webapps/test.xml</code>.</p>
</div>
</div>
<div class="sect4">
<h5 id="quickstart-config-deployer"><a class="anchor" href="#quickstart-config-deployer"></a><a class="link" href="#quickstart-config-deployer">Web Application Deployment</a></h5>
<div class="paragraph">
<p>Jetty is capable of deploying a variety of Web Application formats.
This is accomplished via scans of the <code>${jetty.base}/webapps</code> directory for contexts to deploy.</p>
</div>
<div class="paragraph">
<p>A Context can be any of the following:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A standard WAR file. (must in &#8220;.war&#8221;).</p>
</li>
<li>
<p>A directory containing an expanded WAR file. (must contain <code>{dir}/WEB-INF/web.xml</code> file).</p>
</li>
<li>
<p>A directory containing static content.</p>
</li>
<li>
<p>A XML descriptor in <a href="#jetty-xml-syntax">[jetty-xml-syntax]</a> that configures a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ContextHandler.html">ContextHandler</a> instance (Such as a
<a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html">WebAppContext</a>).</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The new WebAppProvider will attempt to avoid double deployments during the directory scan with the following heuristics:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Hidden files (starting with <code>"."</code>) are ignored</p>
</li>
<li>
<p>Directories with names ending in <code>".d"</code> are ignored</p>
</li>
<li>
<p>If a directory and matching WAR file exist with the same base name (eg: <code>foo/</code> and <code>foo.war</code>), then the directory is assumed to be the unpacked WAR and only the WAR is deployed (which may reuse the unpacked directory)</p>
</li>
<li>
<p>If a directory and matching XML file exists (eg: <code>foo/</code> and <code>foo.xml</code>), then the directory is assumed to be an unpacked WAR and only the XML is deployed (which may use the directory in its own configuration)</p>
</li>
<li>
<p>If a WAR file and matching XML file exist (eg: <code>foo.war</code> and <code>foo.xml</code>), then the WAR is assumed to be configured by the XML and only the XML is deployed.</p>
</li>
</ul>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
In prior versions of Jetty there was a separate ContextDeployer that provided XML-based deployment. As of Jetty 9 the ContextDeployer no longer exists and its functionality has been merged with the new <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/providers/WebAppProvider.html">WebAppProvider</a> to avoid double deployment scenarios.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect4">
<h5 id="_setting-an-authentication-realm"><a class="anchor" href="#_setting-an-authentication-realm"></a><a class="link" href="#_setting-an-authentication-realm">Setting an Authentication Realm</a></h5>
<div class="paragraph">
<p>The authentication method and realm name for a standard web application may be set in the <code>web.xml</code> deployment descriptor with elements like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml">...
<span class="tag">&lt;login-config&gt;</span>
<span class="tag">&lt;auth-method&gt;</span>BASIC<span class="tag">&lt;/auth-method&gt;</span>
<span class="tag">&lt;realm-name&gt;</span>Test Realm<span class="tag">&lt;/realm-name&gt;</span>
<span class="tag">&lt;/login-config&gt;</span>
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>This example declares that the BASIC authentication mechanism will be used with credentials validated against a realm called "Test Realm."
However the standard does not describe how the realm itself is implemented or configured.
In Jetty, there are several realm implementations (called LoginServices) and the simplest of these is the HashLoginService, which can read usernames and credentials from a Java properties file.</p>
</div>
<div class="paragraph">
<p>To configure an instance of HashLoginService that matches the "Test Realm" configured above, the following <code>$JETTY_BASE/etc/test-realm.xml</code> IoC XML file should be passed on the command line or set in <code>start.ini</code> or <code>start.d/server.ini</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml">Unresolved directive in gettingstarted/configuring/what-to-configure.adoc - include::/home/joakim/code/jetty/jetty.project-10.0.x/documentation/jetty-documentation/../tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/test-realm.xml[]</code></pre>
</div>
</div>
<div class="paragraph">
<p>This creates and configures the LoginService as an aggregate bean on the server.
When a web application is deployed that declares a realm called "Test Realm," the server beans are searched for a matching Login Service.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="upgrading-jetty"><a class="anchor" href="#upgrading-jetty"></a><a class="link" href="#upgrading-jetty">Upgrading Jetty</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>Unresolved directive in gettingstarted/upgrading/chapter.adoc - include::upgrading-from-jetty-9.adoc[]</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="http2"><a class="anchor" href="#http2"></a><a class="link" href="#http2">HTTP/2</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="http2-configuring-push"><a class="anchor" href="#http2-configuring-push"></a><a class="link" href="#http2-configuring-push">Configuring HTTP/2 Push</a></h3>
<div class="paragraph">
<p>HTTP/2 Push is a mechanism that allows the server to send multiple resources to the client for a single client request.
This will reduce the amount of round-trips necessary to retrieve all the resources that make up a web page and can significantly improve the page load time.</p>
</div>
<div class="paragraph">
<p>HTTP/2 Push can be automated in your application by configuring a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/servlets/PushCacheFilter.html"><code>PushCacheFilter</code></a> in the <code>web.xml</code>, in this way:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="tag">&lt;web-app</span>
<span class="attribute-name">xmlns</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">http://xmlns.jcp.org/xml/ns/javaee</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">xmlns:xsi</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">http://www.w3.org/2001/XMLSchema-instance</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">xsi:schemaLocation</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">metadata-complete</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">true</span><span class="delimiter">&quot;</span></span>
<span class="attribute-name">version</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">3.1</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
<span class="tag">&lt;filter&gt;</span>
<span class="tag">&lt;filter-name&gt;</span>PushFilter<span class="tag">&lt;/filter-name&gt;</span>
<span class="tag">&lt;filter-class&gt;</span>org.eclipse.jetty.servlets.PushCacheFilter<span class="tag">&lt;/filter-class&gt;</span>
<span class="tag">&lt;async-supported&gt;</span>true<span class="tag">&lt;/async-supported&gt;</span>
<span class="tag">&lt;/filter&gt;</span>
<span class="tag">&lt;filter-mapping&gt;</span>
<span class="tag">&lt;filter-name&gt;</span>PushFilter<span class="tag">&lt;/filter-name&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>/*<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;/filter-mapping&gt;</span>
...
<span class="tag">&lt;/web-app&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p><code>PushCacheFilter</code> analyzes the HTTP requests for resources that arrive to your web application.
Some of these requests contain the HTTP <code>Referer</code> header that points to a resource that has been requested previously.</p>
</div>
<div class="paragraph">
<p>This allows the <code>PushCacheFilter</code> to organize resources in a tree, for example a root <code>index.html</code> resource having two children resources, <code>styles.css</code> and <code>application.js</code>, and <code>styles.css</code> having a child resource, <code>background.png</code>.
The root resource is called the <em>primary</em> resource, while descendant resources are called <em>secondary</em> resources.</p>
</div>
<div class="paragraph">
<p>The resource tree is built using a time window so that when a root resource is requested, only subsequent requests that are made within the time window will be added to the resource tree.
The resource tree can also be limited in size so that the number of secondary resources associated to a primary resource is limited.</p>
</div>
<div class="paragraph">
<p>By default, only the resource <em>path</em> (without the <em>query</em> string) is used to associate secondary resources to the primary resource, but you can configure <code>PushCacheFilter</code> to take the query string into account.</p>
</div>
<div class="paragraph">
<p><code>PushCacheFilter</code> can be configured with the following <code>init-params</code>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>associatePeriod</code>: the time window, in milliseconds, within which a request for a secondary resource will be associated to a primary resource; defaults to 4000 ms</p>
</li>
<li>
<p><code>maxAssociations</code>: the max number of secondary resources that may be associated to a primary resource; defaults to 16</p>
</li>
<li>
<p><code>hosts</code>: a comma separated list of hosts that are allowed in the <code>Referer</code> header; defaults to the host in the <code>Host</code> header</p>
</li>
<li>
<p><code>ports</code>: a comma separated list of ports that are allowed in the <code>Referer</code> header; defaults to the port in the <code>Host</code> header</p>
</li>
<li>
<p><code>useQueryInKey</code>: a boolean indicating whether the query string of the request should be considered when associating secondary resources to primary resources; defaults to <code>false</code></p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="reference-section"><a class="anchor" href="#reference-section"></a><a class="link" href="#reference-section">Jetty XML Reference</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="jetty-xml-usage"><a class="anchor" href="#jetty-xml-usage"></a><a class="link" href="#jetty-xml-usage">Jetty XML Usage</a></h3>
<div class="paragraph">
<p>Jetty provides an XML-based configuration.
It is grounded in Java&#8217;s Reflection API. Classes in the <code>java.lang.reflect</code> represent Java methods and classes, such that you can instantiate objects and invoke their methods based on their names and argument types.
Behind the scenes, Jetty&#8217;s XML config parser translates the XML elements and attributes into Reflection calls.</p>
</div>
<div class="sect3">
<h4 id="using-jettyxml"><a class="anchor" href="#using-jettyxml"></a><a class="link" href="#using-jettyxml">Using jetty.xml</a></h4>
<div class="paragraph">
<p>To use <code>jetty.xml</code>, specify it as a configuration file when running Jetty.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"> java -jar start.jar etc/jetty.xml</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
If you start Jetty without specifying a configuration file, Jetty automatically locates and uses the default installation <code>jetty.xml</code> file.
Therefore <code>java -jar start.jar</code> is equivalent to <code>java -jar start.jar etc/jetty.xml</code> .
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="using-multiple-configuration-files"><a class="anchor" href="#using-multiple-configuration-files"></a><a class="link" href="#using-multiple-configuration-files">Using Multiple Configuration Files</a></h4>
<div class="paragraph">
<p>You are not limited to one configuration file; you can use multiple configuration files when running Jetty, and Jetty will configure the appropriate server instance.
The ID of the server in the <code>&lt;Configure&gt;</code> tag specifies the instance you want to configure.
Each server ID in a configuration file creates a new server instance within the same JVM.
If you use the same ID across multiple configuration files, those configurations are all applied to the same server.</p>
</div>
</div>
<div class="sect3">
<h4 id="setting-parameters-in-configuration-files"><a class="anchor" href="#setting-parameters-in-configuration-files"></a><a class="link" href="#setting-parameters-in-configuration-files">Setting Parameters in Configuration Files</a></h4>
<div class="paragraph">
<p>You can set parameters in configuration files either with system properties (using <code>&lt;SystemProperty&gt;</code>) or properties files (using <code>&lt;Property&gt;</code>) passed via the command line.
For example, this code in <code>jetty.xml</code> allows the port to be defined on the command line, falling back onto `8080`if the port is not specified:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">port</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.http.port</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">8080</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Set&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Then you modify the port while running Jetty by using this command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"> java -Djetty.http.port=<span class="integer">8888</span> -jar start.jar etc/jetty.xml</code></pre>
</div>
</div>
<div class="paragraph">
<p>An example of defining both system properties and properties files from the command line:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"> java -Djetty.http.port=<span class="integer">8888</span> -jar start.jar myjetty.properties etc/jetty.xml etc/other.xml</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="jetty-xml-config"><a class="anchor" href="#jetty-xml-config"></a><a class="link" href="#jetty-xml-config">jetty.xml</a></h3>
<div class="paragraph">
<p><code>jetty.xml</code> is the default configuration file for Jetty, typically located at <code>$JETTY_HOME/etc/jetty.xml</code>. Usually the <code>jetty.xml</code> configures:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The Server class (or subclass if extended) and global options.</p>
</li>
<li>
<p>A ThreadPool (min and max thread).</p>
</li>
<li>
<p>Connectors (ports, timeouts, buffer sizes, protocol).</p>
</li>
<li>
<p>The handler structure (default handlers and/or a contextHandlerCollections).</p>
</li>
<li>
<p>The deployment manager that scans for and deploys webapps and contexts.</p>
</li>
<li>
<p>Login services that provide authentication checking.</p>
</li>
<li>
<p>A request log.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Not all Jetty features are configured in <code>jetty.xml</code>.
There are several optional configuration files that share the same format as <code>jetty.xml</code> and, if specified, concatenate to it.
These configuration files are also stored in <code>$JETTY_HOME/etc/</code>, and examples of them are in <a href="http://github.com/eclipse/jetty.project/jetty-server/src/main/config/etc/">Github Repository</a>.
The selection of which configuration files to use is controlled by <code>start.jar</code> and the process of merging configuration is described in <a href="#jetty-xml-usage">Jetty XML Usage</a>.</p>
</div>
<div class="sect3">
<h4 id="root-element-jetty-xml"><a class="anchor" href="#root-element-jetty-xml"></a><a class="link" href="#root-element-jetty-xml">Root Element</a></h4>
<div class="paragraph">
<p><code>jetty.xml</code> configures an instance of the <code>Jetty org.eclipse.jetty.server.Server.</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="jetty-xml-examples"><a class="anchor" href="#jetty-xml-examples"></a><a class="link" href="#jetty-xml-examples">Examples</a></h4>
<div class="paragraph">
<p><code>$JETTY_HOME/etc</code> contains the default <code>jetty.xml</code>, as well as other sample configuration files (<code>jetty-*.xml</code>) which can be passed to the server via the command line.</p>
</div>
</div>
<div class="sect3">
<h4 id="jetty-xml-additional-resources"><a class="anchor" href="#jetty-xml-additional-resources"></a><a class="link" href="#jetty-xml-additional-resources">Additional Resources</a></h4>
<div class="ulist">
<ul>
<li>
<p><a href="#jetty-xml-syntax">[jetty-xml-syntax]</a> –in-depth reference for Jetty-specific configuration XML syntax.</p>
</li>
<li>
<p><a href="#jetty-xml-config">jetty.xml</a> –configuration file for configuring the entire server</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect2">
<h3 id="jetty-web-xml-config"><a class="anchor" href="#jetty-web-xml-config"></a><a class="link" href="#jetty-web-xml-config">jetty-web.xml</a></h3>
<div class="paragraph">
<p><code>jetty-web.xml</code> is a Jetty configuration file that you can bundle with a specific web application.
The format of <code>jetty-web.xml</code> is the same as <a href="#jetty-xml-config">jetty.xml</a> – it is an XML mapping of the Jetty API.</p>
</div>
<div class="paragraph">
<p>This document offers an overview for using the <code>jetty-web.xml</code> configuration file.
For a more in-depth look at the syntax, see <a href="#jetty-xml-syntax">[jetty-xml-syntax]</a>.</p>
</div>
<div class="sect3">
<h4 id="root-element-jetty-web-xml"><a class="anchor" href="#root-element-jetty-web-xml"></a><a class="link" href="#root-element-jetty-web-xml">Root Element</a></h4>
<div class="paragraph">
<p><code>jetty-web.xml</code> applies on a per-webapp basis, and configures an instance of <code>org.eclipse.jetty.webapp.WebAppContext</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
..
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<i class="fa icon-caution" title="Caution"></i>
</td>
<td class="content">
Make sure you are applying the configuration to an instance of the proper class. <code>jetty-web.xml</code> configures an instance of <code>WebAppContext</code>; <code>jetty.xml</code> configures an instance of <code>Server</code>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="using-jetty-web-xml"><a class="anchor" href="#using-jetty-web-xml"></a><a class="link" href="#using-jetty-web-xml">Using jetty-web.xml</a></h4>
<div class="paragraph">
<p>Place the <code>jetty-web.xml</code> into your web application&#8217;s <code>WEB-INF</code> folder.
When Jetty deploys a web application, it looks for a file called <code>WEB-INF/jetty-web.xml</code> or <code>WEB-INF/web-jetty.xml</code> within the web application (or WAR) and applies the configuration found there.
Be aware that <code>jetty-web.xml</code> is called <em>after</em> all other configuration has been applied to the web application.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
It is important to note that <code>jetty-web.xml</code> files utilize the webapp classpath, not the classpath of the server.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="jetty-web-xml-examples"><a class="anchor" href="#jetty-web-xml-examples"></a><a class="link" href="#jetty-web-xml-examples">jetty-web.xml Examples</a></h4>
<div class="paragraph">
<p>The distribution contains an example of <code>jetty-web.xml</code> inside the WEB-INF folder of the <code>test</code> webapp WAR (<code>$JETTY_HOME/demo-base/webapps/test.war/WEB-INF/jetty-web.xml</code>).</p>
</div>
</div>
<div class="sect3">
<h4 id="additional-jetty-web-xml-resources"><a class="anchor" href="#additional-jetty-web-xml-resources"></a><a class="link" href="#additional-jetty-web-xml-resources">Additional <code>jetty-web.xml</code> Resources</a></h4>
<div class="ulist">
<ul>
<li>
<p><a href="#jetty-xml-syntax">[jetty-xml-syntax]</a> –in-depth reference for Jetty-specific configuration XML syntax.</p>
</li>
<li>
<p><a href="#jetty-xml-config">jetty.xml</a> –configuration file for configuring the entire server</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect2">
<h3 id="jetty-env-xml"><a class="anchor" href="#jetty-env-xml"></a><a class="link" href="#jetty-env-xml">jetty-env.xml</a></h3>
<div class="paragraph">
<p><code>jetty-env.xml</code> is an optional Jetty file that configures JNDI resources for an individual webapp.
The format of <code>jetty-env.xml</code> is the same as <a href="#jetty-xml-config">jetty.xml</a> –it is an XML mapping of the Jetty API.</p>
</div>
<div class="paragraph">
<p>When Jetty deploys a web application, it automatically looks for a file called ` WEB-INF/jetty-env.xml` within the web application (or WAR), and sets up the webapp naming environment so that naming references in the <code>WEB-INF/web.xml</code> file can be resolved from the information provided in the <code>WEB-INF/jetty-env.xml</code> and <a href="#jetty-xml-config">jetty.xml</a> files.
You define global naming resources on the server via <code>jetty.xml</code>.</p>
</div>
<div class="sect3">
<h4 id="jetty-env-root-element"><a class="anchor" href="#jetty-env-root-element"></a><a class="link" href="#jetty-env-root-element">jetty-env.xml Root Element</a></h4>
<div class="paragraph">
<p>Jetty applies <code>jetty-env.xml</code> on a per-webapp basis, and configures an instance of <code>org.eclipse.jetty.webapp.WebAppContext.</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
..
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<i class="fa icon-caution" title="Caution"></i>
</td>
<td class="content">
Make sure you are applying the configuration to an instance of the proper class. <code>jetty-env.xml</code> configures an instance of WebAppContext, and not an instance of Server.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="using-jetty-env-xml"><a class="anchor" href="#using-jetty-env-xml"></a><a class="link" href="#using-jetty-env-xml">Using <code>jetty-env.xml</code></a></h4>
<div class="paragraph">
<p>Place the <code>jetty-env.xml</code> file in your web application&#8217;s WEB-INF folder.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="preprocessor">&lt;?xml version=&quot;1.0&quot;?&gt;</span>
<span class="doctype">&lt;!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;https://www.eclipse.org/jetty/configure_9_3.dtd&quot;&gt;</span>
<span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="comment">&lt;!-- Add an EnvEntry only valid for this webapp --&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">gargle</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.EnvEntry</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>gargle<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.lang.Double</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>100<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">boolean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="comment">&lt;!-- Add an override for a global EnvEntry --&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">wiggle</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.EnvEntry</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>wiggle<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.lang.Double</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>55.0<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">boolean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="comment">&lt;!-- an XADataSource --&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">mydatasource99</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/mydatasource99<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.atomikos.jdbc.SimpleDataSourceBean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">xaDataSourceClassName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>org.apache.derby.jdbc.EmbeddedXADataSource<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">xaDataSourceProperties</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>databaseName=testdb99;createDatabase=create<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">UniqueResourceName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>mydatasource99<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="additional-jetty-env-xml-resources"><a class="anchor" href="#additional-jetty-env-xml-resources"></a><a class="link" href="#additional-jetty-env-xml-resources">Additional jetty-env.xml Resources</a></h4>
<div class="ulist">
<ul>
<li>
<p><a href="#jetty-xml-syntax">[jetty-xml-syntax]</a> –In-depth reference for Jetty-specific configuration XML syntax.</p>
</li>
<li>
<p><a href="#jetty-xml-config">jetty.xml</a> –Configuration file for configuring the entire server.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect2">
<h3 id="webdefault-xml"><a class="anchor" href="#webdefault-xml"></a><a class="link" href="#webdefault-xml">webdefault.xml</a></h3>
<div class="paragraph">
<p>The <code>webdefault.xml</code> file saves web applications from having to define a lot of house-keeping and container-specific elements in their own <code>web.xml</code> files.
For example, you can use it to set up MIME-type mappings and JSP servlet-mappings.
Jetty applies <code>webdefault.xml</code> to a web application <em>before</em> the application&#8217;s own <code>WEB-INF/web.xml</code>, which means that it <strong>cannot</strong> override values inside the webapp&#8217;s <code>web.xml</code>.
It uses the <a href="#jetty-xml-config">jetty.xml</a> syntax.
Generally, it is convenient for all webapps in a Jetty instance to share the same <code>webdefault.xml</code> file.
However, it is certainly possible to provide differentiated ` webdefault.xml` files for individual web applications.</p>
</div>
<div class="paragraph">
<p>The <code>webdefault.xml</code> file is located in <code>$(jetty.home)/etc/webdefault.xml</code>.</p>
</div>
<div class="sect3">
<h4 id="using-webdefault-xml"><a class="anchor" href="#using-webdefault-xml"></a><a class="link" href="#using-webdefault-xml">Using webdefault.xml</a></h4>
<div class="paragraph">
<p>You can specify a custom configuration file to use for specific webapps, or for all webapps. If you do not specify an alternate defaults descriptor, the <code>$JETTY-HOME/etc/jetty-deploy.xml</code> file will configure jetty to automatically use <code>$JETTY_HOME/etc/webdefault.xml</code>.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>To ensure your <code>webdefault.xml</code> files are validated, you will need to set the <code>validateXml</code> attribute to true as described <a href="#jetty-xml-dtd">here.</a></p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The <code>webdefault.xml</code> <a href="{GITBROWSEURLSURL}/jetty-webapp/src/main/config/etc/webdefault.xml">included with the Jetty Distribution</a> contains several configuration options, such as init params and servlet mappings, and is separated into sections for easy navigation.
Some of the more common options include, but are not limited to:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">dirAllowed</dt>
<dd>
<p>If true, directory listings are returned if no welcome file is found.
Otherwise 403 Forbidden displays.</p>
</dd>
<dt class="hdlist1">precompressed</dt>
<dd>
<p>If set to a comma separated list of file extensions, these indicate compressed formats that are known to map to a MIME-type that may be listed in a requests Accept-Encoding header.
If set to a boolean True, then a default set of compressed formats will be used, otherwise no pre-compressed formats.</p>
</dd>
<dt class="hdlist1">maxCacheSize</dt>
<dd>
<p>Maximum total size of the cache or 0 for no cache.</p>
</dd>
<dt class="hdlist1">maxCachedFileSize</dt>
<dd>
<p>Maximum size of a file to cache.</p>
</dd>
<dt class="hdlist1">maxCachedFiles</dt>
<dd>
<p>Maximum number of files to cache.</p>
</dd>
</dl>
</div>
<div class="sect4">
<h5 id="creating-custom-webdefault-xml-one-webapp"><a class="anchor" href="#creating-custom-webdefault-xml-one-webapp"></a><a class="link" href="#creating-custom-webdefault-xml-one-webapp">Creating a Custom webdefault.xml for One WebApp</a></h5>
<div class="paragraph">
<p>You can specify a custom <code>webdefault.xml</code> for an individual web application in that webapp&#8217;s <a href="#jetty-xml-config">jetty.xml</a> as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
<span class="comment">&lt;!-- Set up the absolute path to the custom webdefault.xml --&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">defaultsDescriptor</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/my/path/to/webdefault.xml<span class="tag">&lt;/Set&gt;</span>
...
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The equivalent in code is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">org.eclipse.jetty.webapp.WebAppContext</span>;
...
WebAppContext wac = <span class="keyword">new</span> WebAppContext();
...
<span class="comment">//Set up the absolute path to the custom webdefault.xml.</span>
wac.setDefaultsDescriptor(<span class="string"><span class="delimiter">&quot;</span><span class="content">/my/path/to/webdefault.xml</span><span class="delimiter">&quot;</span></span>);
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>Alternatively, you can use a <a href="#jetty-classloading">Jetty Classloading</a> to find the resource representing your custom <code>webdefault.xml</code>.</p>
</div>
</div>
<div class="sect4">
<h5 id="creating-custom-webdefault-xml-multiple-webapps"><a class="anchor" href="#creating-custom-webdefault-xml-multiple-webapps"></a><a class="link" href="#creating-custom-webdefault-xml-multiple-webapps">Creating a Custom webdefault.xml for Multiple WebApps</a></h5>
<div class="paragraph">
<p>If you want to apply the same custom <code>webdefault.xml</code> to a number of webapps, provide the path to the file in <a href="#jetty-xml-config">jetty.xml</a> in the <code>$JETTY_HOME/etc/jetty-deploy.xml</code> file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">defaultsDescriptor</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>/other/path/to/another/webdefault.xml<span class="tag">&lt;/Set&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="webdefault-xml-using-jetty-maven-plugin"><a class="anchor" href="#webdefault-xml-using-jetty-maven-plugin"></a><a class="link" href="#webdefault-xml-using-jetty-maven-plugin">Using the Jetty Maven Plugin</a></h5>
<div class="paragraph">
<p>Similarly, when using the <a href="#jetty-maven-plugin">Jetty Maven Plugin</a> you provide a customized <code>webdefault.xml</code> file for your webapp as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project&gt;</span>
...
<span class="tag">&lt;plugins&gt;</span>
<span class="tag">&lt;plugin&gt;</span>
...
<span class="tag">&lt;artifactId&gt;</span>jetty-maven-plugin<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;configuration&gt;</span>
<span class="tag">&lt;webApp&gt;</span>
...
<span class="tag">&lt;defaultsDescriptor&gt;</span>/my/path/to/webdefault.xml<span class="tag">&lt;/defaultsDescriptor&gt;</span>
<span class="tag">&lt;/webApp&gt;</span>
<span class="tag">&lt;/configuration&gt;</span>
<span class="tag">&lt;/plugin&gt;</span>
...
<span class="tag">&lt;/plugins&gt;</span>
...
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="webdefault-xml-additional-resources"><a class="anchor" href="#webdefault-xml-additional-resources"></a><a class="link" href="#webdefault-xml-additional-resources">Additional Resources</a></h5>
<div class="ulist">
<ul>
<li>
<p><a href="#jetty-web-xml-config">jetty-web.xml</a> –Reference for <code>web.xml</code> files</p>
</li>
<li>
<p><a href="#override-web-xml">Jetty override-web.xml</a> –Information for this <code>web.xml</code> -formatted file, applied after the webapp&#8217;s <code>web.xml</code> webapp.</p>
</li>
<li>
<p><a href="#jetty-xml-config">jetty.xml</a> –Reference for <code>jetty.xml</code> files</p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="override-web-xml"><a class="anchor" href="#override-web-xml"></a><a class="link" href="#override-web-xml">Jetty override-web.xml</a></h3>
<div class="paragraph">
<p>To deploy a web application or WAR into different environments, most likely you will need to customize the webapp for compatibility with each environment.
The challenge is to do so without changing the webapp itself. You can use a <code>jetty.xml</code> file for some of this work since it is not part of the webapp.
But there are some changes that <code>jetty.xml</code> cannot accomplish, for example, modifications to servlet init-params and context init-params.
Using <code>webdefault.xml</code> is not an option because Jetty applies <code>webdefault.xml</code> to a web application <em>before</em> the application&#8217;s own <code>WEB-INF/web.xml</code>, which means that it cannot override values inside the webapp&#8217;s ` web.xml`.</p>
</div>
<div class="paragraph">
<p>The solution is <code>override-web.xml</code>.
It is a <code>web.xml</code> file that Jetty applies to a web application <em>after</em> the application&#8217;s own <code>WEB-INF/web.xml</code>, which means that it can override values or add new elements.
This is defined on a per-webapp basis, using the <a href="#jetty-xml-syntax">[jetty-xml-syntax]</a>.</p>
</div>
<div class="sect3">
<h4 id="using-override-web-xml"><a class="anchor" href="#using-override-web-xml"></a><a class="link" href="#using-override-web-xml">Using override-web.xml</a></h4>
<div class="paragraph">
<p>You can specify the <code>override-web.xml</code> to use for an individual web application in a deployable xml file located in Jetty webapps folder .
For example, if you had a webapp named MyApp, you would place a deployable xml file named <code>myapp.xml</code> in <code>${jetty.base}/webapps</code> which includes an <code>overrideDescriptor</code> entry for the <code>override-web.xml</code> file.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
<span class="comment">&lt;!-- Set up the path to the custom override descriptor,
relative to your $(jetty.home) directory or to the current directory --&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">overrideDescriptor</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/my/path/to/override-web.xml<span class="tag">&lt;/Set&gt;</span>
...
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The equivalent in code is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">org.eclipse.jetty.webapp.WebAppContext</span>;
...
WebAppContext wac = <span class="keyword">new</span> WebAppContext();
...
<span class="comment">//Set the path to the override descriptor, based on your $(jetty.home) directory</span>
wac.setOverrideDescriptor(<span class="predefined-type">System</span>.getProperty(<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span>)+<span class="string"><span class="delimiter">&quot;</span><span class="content">/my/path/to/override-web.xml</span><span class="delimiter">&quot;</span></span>);
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>Alternatively, you can use the classloader (<a href="#jetty-classloading">Jetty Classloading</a>) to get the path to the override descriptor as a resource.</p>
</div>
</div>
<div class="sect3">
<h4 id="override-using-jetty-maven-plugin"><a class="anchor" href="#override-using-jetty-maven-plugin"></a><a class="link" href="#override-using-jetty-maven-plugin">Using the Jetty Maven Plugin</a></h4>
<div class="paragraph">
<p>Use the <code>&lt;overrideDescriptor&gt;</code> tag as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;project&gt;</span>
...
<span class="tag">&lt;plugins&gt;</span>
<span class="tag">&lt;plugin&gt;</span>
...
<span class="tag">&lt;artifactId&gt;</span>jetty-maven-plugin<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;configuration&gt;</span>
<span class="tag">&lt;webAppConfig&gt;</span>
...
<span class="tag">&lt;overrideDescriptor&gt;</span>src/main/resources/override-web.xml<span class="tag">&lt;/overrideDescriptor&gt;</span>
<span class="tag">&lt;/webAppConfig&gt;</span>
<span class="tag">&lt;/configuration&gt;</span>
<span class="tag">&lt;/plugin&gt;</span>
...
<span class="tag">&lt;/plugins&gt;</span>
...
<span class="tag">&lt;/project&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="override-web-xml-additional-resources"><a class="anchor" href="#override-web-xml-additional-resources"></a><a class="link" href="#override-web-xml-additional-resources">Additional Resources</a></h4>
<div class="ulist">
<ul>
<li>
<p><a href="#webdefault-xml">webdefault.xml</a> –Information for this <code>web.xml</code> -formatted file, applied before the webapp&#8217;s <code>web.xml</code> webapp.</p>
</li>
<li>
<p><a href="#jetty-xml-config">jetty.xml</a> –Reference for <code>jetty.xml</code> files</p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="jmx-chapter"><a class="anchor" href="#jmx-chapter"></a><a class="link" href="#jmx-chapter">Java Management Extensions (JMX)</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>The <a href="http://java.sun.com/products/JavaManagement/">Java Management Extensions (JMX) API</a> is a standard API for managing and monitoring resources such as applications, devices, services, and the Java virtual machine.</p>
</div>
<div class="paragraph">
<p>Typical uses of the JMX technology include:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Consulting and changing application configuration</p>
</li>
<li>
<p>Accumulating and making available statistics about application behavior</p>
</li>
<li>
<p>Notifying of state changes and erroneous conditions</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The JMX API includes remote access, so a remote management program can interact with a running application for these purposes.</p>
</div>
<div class="sect2">
<h3 id="jetty-jmx-annotations"><a class="anchor" href="#jetty-jmx-annotations"></a><a class="link" href="#jetty-jmx-annotations">Jetty JMX Annotations</a></h3>
<div class="paragraph">
<p>When the <code>jetty-jmx</code> libraries are present on startup and the wiring is enabled for exposing Jetty MBeans to JMX, there are three annotations that govern when and how MBeans are created and exposed.</p>
</div>
<div class="sect3">
<h4 id="jmx-annotation-introspection"><a class="anchor" href="#jmx-annotation-introspection"></a><a class="link" href="#jmx-annotation-introspection">Annotation Introspection</a></h4>
<div class="paragraph">
<p>When JMX is configured and enabled in Jetty, any time an object is registered with the Server it is introspected as a potential MBean to be exposed.
This introspection proceeds as follows assuming the class is named <code>com.acme.Foo</code>:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>All influences for <code>com.acme.Foo</code> determined.
These include each class in the chain of super classes, and by convention each of these classes following a form of <code>com.acme.jmx.FooMBean</code>.
All super classes and their corresponding MBean representations are then used in the next step.</p>
</li>
<li>
<p>Each potential influencing class is checked for the <code>@ManagedObject</code> annotation.
Should this annotation exist at any point in the chain of influencers then an MBran is created with the description of the version <code>@ManagedObject</code> discovered.</p>
</li>
<li>
<p>Once a MBean has been created for an object then each potential influencing object is introspected for <code>@ManagedAttribute</code> and <code>@ManagedOperation</code> annotations and the corresponding type is exposed to the MBean.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>The convention of looking for <code>@ManagedObject</code> annotations on <code>.jmx.ClassMBean</code> allows for a normal POJOs to be wrapped in an MBean without itself without requiring it being marked up with annotations.
Since the POJO is passed to these wrapped derived Mbean instances and is an internal variable then the MBean can be used to better expose a set of attributes and operations that may not have been anticipated when the original object was created.</p>
</div>
</div>
<div class="sect3">
<h4 id="jmx-managed-object"><a class="anchor" href="#jmx-managed-object"></a><a class="link" href="#jmx-managed-object">@ManagedObject</a></h4>
<div class="paragraph">
<p>The <code>@ManagedObject</code> annotation is used on a class at the top level to indicate that it should be exposed as an MBean.
It has only one attribute to it which is used as the description of the MBean.
Should multiple <code>@ManagedObject</code> annotations be found in the chain of influence then the first description is used.</p>
</div>
<div class="paragraph">
<p>The list of attributes available are:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">value</dt>
<dd>
<p>The description of the Managed Object.</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="jmx-managed-attribute"><a class="anchor" href="#jmx-managed-attribute"></a><a class="link" href="#jmx-managed-attribute">@ManagedAttribute</a></h4>
<div class="paragraph">
<p>The <code>@ManagedAttribute</code> annotation is used to indicate that a given method exposes a JMX attribute.
This annotation is placed always on the reader method of a given attribute.
Unless it is marked as read-only in the configuration of the annotation a corresponding setter is looked for following normal naming conventions.
For example if this annotation is on a method called <code>getFoo()</code> then a method called <code>setFoo()</code> would be looked for and if found wired automatically into the JMX attribute.</p>
</div>
<div class="paragraph">
<p>The list of attributes available are:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">value</dt>
<dd>
<p>The description of the Managed Attribute.</p>
</dd>
<dt class="hdlist1">name</dt>
<dd>
<p>The name of the Managed Attribute.</p>
</dd>
<dt class="hdlist1">proxied</dt>
<dd>
<p>Value is true if the corresponding MBean for this object contains the method of this JMX attribute in question.</p>
</dd>
<dt class="hdlist1">readonly</dt>
<dd>
<p>By default this value is false which means that a corresponding setter will be looked for an wired into the attribute should one be found.
Setting this to true make the JMX attribute read only.</p>
</dd>
<dt class="hdlist1">setter</dt>
<dd>
<p>This attribute can be used when the corresponding setter for a JMX attribute follows a non-standard naming convention and it should still be exposed as the setter for the attribute.</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="jmx-managed-operation"><a class="anchor" href="#jmx-managed-operation"></a><a class="link" href="#jmx-managed-operation">@ManagedOperation</a></h4>
<div class="paragraph">
<p>The <code>@ManagedOperation</code> annotation is used to indicate that a given method should be considered a JMX operation.</p>
</div>
<div class="paragraph">
<p>The list of attributes available are:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">value</dt>
<dd>
<p>The description of the Managed Operation.</p>
</dd>
<dt class="hdlist1">impact</dt>
<dd>
<p>The impact of an operation.
By default this value is "UNKNOWN" and acceptable values are "ACTION", "INFO", "ACTION_INFO" and should be used according to their definitions with JMX.</p>
</dd>
<dt class="hdlist1">proxied</dt>
<dd>
<p>Value is true if the corresponding MBean for this object contains the method of this JMX operation in question.</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="jmx-name-annotation"><a class="anchor" href="#jmx-name-annotation"></a><a class="link" href="#jmx-name-annotation">@Name</a></h4>
<div class="paragraph">
<p>A fourth annotation is often used in conjunction with the JMX annotations mentioned above.
This annotation is used to describe variables in method signatures so that when rendered into tools like JConsole it is clear what the parameters are.
For example:</p>
</div>
<div class="paragraph">
<p>The list of attributes available are:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">value</dt>
<dd>
<p>The name of the parameter.</p>
</dd>
<dt class="hdlist1">description</dt>
<dd>
<p>The description of the parameter.</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="jmx-annotation-example"><a class="anchor" href="#jmx-annotation-example"></a><a class="link" href="#jmx-annotation-example">Example</a></h4>
<div class="paragraph">
<p>The following is an example of each of the annotations mentioned above in practice.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">package</span> <span class="namespace">com.acme</span>;
<span class="keyword">import</span> <span class="include">org.eclipse.jetty.util.annotation.ManagedAttribute</span>;
<span class="keyword">import</span> <span class="include">org.eclipse.jetty.util.annotation.ManagedObject</span>;
<span class="keyword">import</span> <span class="include">org.eclipse.jetty.util.annotation.ManagedOperation</span>;
<span class="keyword">import</span> <span class="include">org.eclipse.jetty.util.annotation.Name</span>;
<span class="annotation">@ManagedObject</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">Test MBean Annotations</span><span class="delimiter">&quot;</span></span>)
<span class="directive">public</span> <span class="type">class</span> <span class="class">Derived</span> <span class="directive">extends</span> Base <span class="directive">implements</span> <span class="predefined-type">Signature</span>
{
<span class="predefined-type">String</span> fname=<span class="string"><span class="delimiter">&quot;</span><span class="content">Full Name</span><span class="delimiter">&quot;</span></span>;
<span class="annotation">@ManagedAttribute</span>(value=<span class="string"><span class="delimiter">&quot;</span><span class="content">The full name of something</span><span class="delimiter">&quot;</span></span>, name=<span class="string"><span class="delimiter">&quot;</span><span class="content">fname</span><span class="delimiter">&quot;</span></span>)
<span class="directive">public</span> <span class="predefined-type">String</span> getFullName()
{
<span class="keyword">return</span> fname;
}
<span class="directive">public</span> <span class="type">void</span> setFullName(<span class="predefined-type">String</span> name)
{
fname=name;
}
<span class="annotation">@ManagedOperation</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">Doodle something</span><span class="delimiter">&quot;</span></span>)
<span class="directive">public</span> <span class="type">void</span> doodle(<span class="annotation">@Name</span>(value=<span class="string"><span class="delimiter">&quot;</span><span class="content">doodle</span><span class="delimiter">&quot;</span></span>, description=<span class="string"><span class="delimiter">&quot;</span><span class="content">A description of the argument</span><span class="delimiter">&quot;</span></span>) <span class="predefined-type">String</span> doodle)
{
<span class="predefined-type">System</span>.err.println(<span class="string"><span class="delimiter">&quot;</span><span class="content">doodle </span><span class="delimiter">&quot;</span></span>+doodle);
}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="jetty-jconsole"><a class="anchor" href="#jetty-jconsole"></a><a class="link" href="#jetty-jconsole">Managing Jetty with JConsole and JMC</a></h3>
<div class="paragraph">
<p>JConsole and the Java Mission Control (JMX) are graphical tools; they allow you to remotely manage and monitor your server and web application status using JMX.
When following the instructions given below, please also ensure that you make any necessary changes to any anti-virus software you may be using which may prevent JConsole or JMC from running.</p>
</div>
<div class="sect3">
<h4 id="_starting-jetty-standalone"><a class="anchor" href="#_starting-jetty-standalone"></a><a class="link" href="#_starting-jetty-standalone">Starting Jetty Standalone</a></h4>
<div class="paragraph">
<p>The simplest way to enable support is to add the JMX-Remote support module to your <code>{$jetty.base}</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=jmx-remote, jmx
INFO: jmx-remote initialised in ${jetty.base}/start.ini
INFO: jmx initialised in ${jetty.base}/start.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>Then open the <code>{$jetty.base}/start.ini</code> (or <code>{$jetty.base}/start.d/jmx-remote.ini</code>) file and edit the properties to suit your needs:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">#
# Initialize module jmx-remote
#
--module=jmx-remote
## JMX Configuration
## Enable for an open port accessible by remote machines
jetty.jmxrmihost=localhost
jetty.jmxrmiport=1099</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="jetty-jconsole-monitoring"><a class="anchor" href="#jetty-jconsole-monitoring"></a><a class="link" href="#jetty-jconsole-monitoring">Monitoring Jetty with JConsole</a></h4>
<div class="paragraph">
<p>To monitor Jetty&#8217;s server status with JConsole, start Jetty and then start JConsole by typing <code>jconsole</code> on the command line.</p>
</div>
<div class="sect4">
<h5 id="_connecting-to-your-server-process"><a class="anchor" href="#_connecting-to-your-server-process"></a><a class="link" href="#_connecting-to-your-server-process">Connecting to your server process</a></h5>
<div class="paragraph">
<p>After you start Jetty, you will see a dialog box in JConsole with a list of running processes to which you can connect.
It should look something like so:</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="jconsole1.jpg" alt="image" width="576"></span></p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
If you don&#8217;t see your Jetty process in the list of processes you can connect to, quickly switch tabs, or close and reopen a new "New Connection" dialog window.
This forces JConsole to refresh the list, and recognize your newly-started Jetty process.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>Select the start.jar entry and click the "Connect" button.
A new JConsole window opens:</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="jconsole2.jpg" alt="image" width="576"></span></p>
</div>
<div class="paragraph">
<p>From this window you can monitor memory usage, thread usage, classloading and VM statistics.
You can also perform operations such as a manual garbage collect.
JConsole is an extremely powerful and useful tool.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_managing-jetty-objects-with-jconsole"><a class="anchor" href="#_managing-jetty-objects-with-jconsole"></a><a class="link" href="#_managing-jetty-objects-with-jconsole">Managing Jetty Objects with JConsole</a></h4>
<div class="paragraph">
<p>The MBean tab of JConsole allows access to managed objects within the Java application, including MBeans the JVM provides.
If you also want to interact with the Jetty JMX implementation via JConsole, you need to start Jetty JMX in a form that JConsole can access.
See <a href="#using-jmx">[using-jmx]</a> for more information.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="jconsole3.png" alt="image" width="576"></span></p>
</div>
</div>
<div class="sect3">
<h4 id="jetty-jmc-monitoring"><a class="anchor" href="#jetty-jmc-monitoring"></a><a class="link" href="#jetty-jmc-monitoring">Monitoring Jetty with JMC</a></h4>
<div class="paragraph">
<p>To monitor Jetty&#8217;s server status with JMC, start Jetty and then start JMC by typing <code>jmc</code> on the command line.</p>
</div>
<div class="sect4">
<h5 id="_connecting-to-your-server-process-2"><a class="anchor" href="#_connecting-to-your-server-process-2"></a><a class="link" href="#_connecting-to-your-server-process-2">Connecting to your server process</a></h5>
<div class="paragraph">
<p>After you start Jetty, you will see a dialog box in JMC with a list of running processes to which you can connect.
It should look something like so:</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="jmc1.png" alt="image" width="576"></span></p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
If you don&#8217;t see your Jetty process in the list of processes you can connect to, quickly switch tabs, or close and reopen a new "New Connection" dialog window.
This forces JMC to refresh the list, and recognize your newly-started Jetty process.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>Double-click the start.jar entry or right-click the start.jar entry and select "Start JMX Console".
A new JMC window opens on the right:</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="jmc2.png" alt="image" width="576"></span></p>
</div>
<div class="paragraph">
<p>From this window you can monitor memory usage, thread usage, classloading and VM statistics.
You can also perform operations such as a manual garbage collect.
JMC is an extremely powerful and useful tool.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_managing-jetty-objects-with-jconsole-2"><a class="anchor" href="#_managing-jetty-objects-with-jconsole-2"></a><a class="link" href="#_managing-jetty-objects-with-jconsole-2">Managing Jetty Objects with JConsole</a></h4>
<div class="paragraph">
<p>The MBean tab of JMC allows access to managed objects within the Java application, including MBeans the JVM provides.
If you also want to interact with the Jetty JMX implementation via JMC, you need to start Jetty JMX in a form that JMC can access.
See <a href="#using-jmx">[using-jmx]</a> for more information.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="jmc3.png" alt="image" width="576"></span></p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="jndi"><a class="anchor" href="#jndi"></a><a class="link" href="#jndi">Configuring JNDI</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>Jetty supports <code>java:comp/env</code> lookups in webapps.
This is an optional feature for which some configuration is required.</p>
</div>
<div class="sect2">
<h3 id="using-jetty-jndi"><a class="anchor" href="#using-jetty-jndi"></a><a class="link" href="#using-jetty-jndi">Working with Jetty JNDI</a></h3>
<div class="sect3">
<h4 id="_defining-the-web-xml"><a class="anchor" href="#_defining-the-web-xml"></a><a class="link" href="#_defining-the-web-xml">Defining the web.xml</a></h4>
<div class="paragraph">
<p>You can configure naming resources to reference in a <code>web.xml</code> file and access from within the <code>java:comp/env</code> naming environment of the webapp during execution.
Specifically, you can configure support for the following <code>web.xml</code> elements:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;env-entry</span><span class="tag">/&gt;</span>
<span class="tag">&lt;resource-ref</span><span class="tag">/&gt;</span>
<span class="tag">&lt;resource-env-ref</span><span class="tag">/&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p><a href="#configuring-jndi-env-entries">Configuring env-entries</a> shows you how to set up overrides for <code>env-entry</code> elements in <code>web.xml</code>, while <a href="#configuring-resource-refs-and-resource-env-refs">Configuring <code>resource-refs</code> and <code>resource-env-refs</code></a> discusses how to configure support resources such as <code>javax.sql.DataSource</code>.</p>
</div>
<div class="paragraph">
<p>You can also plug a JTA <code>javax.transaction.UserTransaction</code> implementation into Jetty so that webapps can look up <code>java:comp/UserTransaction</code> to obtain a distributed transaction manager: see <a href="#configuring-xa-transactions">Configuring XA Transactions</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="defining-jndi-naming-entries"><a class="anchor" href="#defining-jndi-naming-entries"></a><a class="link" href="#defining-jndi-naming-entries">Declaring Resources</a></h4>
<div class="paragraph">
<p>You must declare the objects you want bound into the Jetty environment so that you can then hook into your webapp via <code>env-entry</code>, <code>resource-ref</code> and <code>resource-env-refs</code> in <code>web.xml</code>.
You create these bindings by using declarations of the following types:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>org.eclipse.jetty.plus.jndi.EnvEntry</code></dt>
<dd>
<p>For <code>env-entry</code> type of entries</p>
</dd>
<dt class="hdlist1"><code>org.eclipse.jetty.plus.jndi.Resource</code></dt>
<dd>
<p>For all other type of resources</p>
</dd>
<dt class="hdlist1"><code>org.eclipse.jetty.plus.jndi.Transaction</code></dt>
<dd>
<p>For a JTA manager</p>
</dd>
<dt class="hdlist1"><code>org.eclipse.jetty.plus.jndi.Link</code></dt>
<dd>
<p>For the link between a <code>web.xml</code> resource name and a naming entry</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Declarations of each of these types follow the same general pattern:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.xxxx</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="comment">&lt;!-- scope --&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="comment">&lt;!-- name --&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="comment">&lt;!-- value --&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>You can place these declarations into three different files, depending on your needs and the <a href="#jndi-name-scope">scope</a> of the resources being declared.</p>
</div>
</div>
<div class="sect3">
<h4 id="jndi-where-to-declare"><a class="anchor" href="#jndi-where-to-declare"></a><a class="link" href="#jndi-where-to-declare">Deciding Where to Declare Resources</a></h4>
<div class="paragraph">
<p>You can define naming resources in three places:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><em>jetty.xml</em></dt>
<dd>
<p>Naming resources defined in a <code>jetty.xml</code> file are <a href="#jndi-name-scope">scoped</a> at either the JVM level or the Server level.
The classes for the resource must be visible at the Jetty container level.
If the classes for the resource only exist inside your webapp, you must declare it in a <code>WEB-INF/jetty-env.xml</code> file.</p>
</dd>
<dt class="hdlist1">WEB-INF/jetty-env.xml</dt>
<dd>
<p>Naming resources in a <code>WEB-INF/jetty-env.xml</code> file are <a href="#jndi-name-scope">scoped</a> to the web app in which the file resides.
While you can enter JVM or Server scopes if you choose, we do not recommend doing so.
The resources defined here may use classes from inside your webapp.
This is a Jetty-specific mechanism.</p>
</dd>
<dt class="hdlist1">Context xml file</dt>
<dd>
<p>Entries in a context xml file should be <a href="#jndi-name-scope">scoped</a> at the level of the webapp to which they apply, although you can supply a less strict scoping level of Server or JVM if you choose.
As with resources declared in a <code>jetty.xml</code> file, classes associated with the resource must be visible on the container&#8217;s classpath.</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="jndi-name-scope"><a class="anchor" href="#jndi-name-scope"></a><a class="link" href="#jndi-name-scope">Scope of Resource Names</a></h4>
<div class="paragraph">
<p>Naming resources within Jetty belong to one of three different scopes, in increasing order of restrictiveness:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">JVM scope</dt>
<dd>
<p>The name is unique across the JVM instance, and is visible to all application code.
You represent this scope by a <code>null</code> first parameter to the resource declaration.
For example:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">cf</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span> <span class="comment">&lt;!-- empty arg --&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jms/connectionFactory<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.apache.activemq.ActiveMQConnectionFactory</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>vm://localhost?broker.persistent=false<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">Server scope</dt>
<dd>
<p>The name is unique to a Server instance, and is only visible to code associated with that instance.
You represent this scope by referencing the Server instance as the first parameter to the resource declaration.
For example:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">cf</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span> <span class="comment">&lt;!-- reference to Server instance --&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jms/connectionFactory<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.apache.activemq.ActiveMQConnectionFactory</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>vm://localhost?broker.persistent=false<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</dd>
<dt class="hdlist1">Webapp scope</dt>
<dd>
<p>The name is unique to the WebAppContext instance, and is only visible to code associated with that instance.
You represent this scope by referencing the <code>WebAppContext</code> instance as the first parameter to the resource declaration.
For example:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">'</span><span class="content">wac</span><span class="delimiter">'</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">cf</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">'</span><span class="content">wac</span><span class="delimiter">'</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span> <span class="comment">&lt;!-- reference to WebAppContext --&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jms/connectionFactory<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.apache.activemq.ActiveMQConnectionFactory</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>vm://localhost?broker.persistent=false<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="binding-objects-into-jetty-jndi"><a class="anchor" href="#binding-objects-into-jetty-jndi"></a><a class="link" href="#binding-objects-into-jetty-jndi">What Can Be Bound as a Resource?</a></h4>
<div class="paragraph">
<p>You can bind four types of objects into a Jetty JNDI reference:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>An ordinary POJO instance.</p>
</li>
<li>
<p>A <a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/naming/Reference.html">javax.naming.Reference</a> instance.</p>
</li>
<li>
<p>An object instance that implements the <a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/naming/Referenceable.html">javax.naming.Referenceable</a> interface.</p>
</li>
<li>
<p>A link between a name as referenced in <code>web.xml</code> and as referenced in the Jetty environment.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect2">
<h3 id="jndi-configuration"><a class="anchor" href="#jndi-configuration"></a><a class="link" href="#jndi-configuration">Configuring JNDI</a></h3>
<div class="sect3">
<h4 id="configuring-jndi-env-entries"><a class="anchor" href="#configuring-jndi-env-entries"></a><a class="link" href="#configuring-jndi-env-entries">Configuring JNDI <em>env-entries</em></a></h4>
<div class="paragraph">
<p>Sometimes it is useful to pass configuration information to a webapp at runtime that you either cannot or cannot conveniently code into a <code>web.xml</code> env-entry.
In such cases, you can use the <code>org.eclipse.jetty.plus.jndi.EnvEntry</code> class, and even override an entry of the same name in <code>web.xml</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.EnvEntry</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>mySpecialValue<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.lang.Integer</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>4000<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">boolean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This example defines a virtual <code>env-entry</code> called <code>mySpecialValue</code> with value <code>4000</code> that is <a href="#jndi-name-scope">scoped</a> to the JVM.
It is put into JNDI at <code>java:comp/env/mySpecialValue</code> for <em>every</em> web app deployed.
Moreover, the boolean argument indicates that this value overrides an <code>env-entry</code> of the same name in <code>web.xml</code>.
If you don&#8217;t want to override, omit this argument, or set it to <code>false</code>.</p>
</div>
<div class="paragraph">
<p>The Servlet Specification allows binding only the following object types to an <code>env-entry</code>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>java.lang.String</p>
</li>
<li>
<p>java.lang.Integer</p>
</li>
<li>
<p>java.lang.Float</p>
</li>
<li>
<p>java.lang.Double</p>
</li>
<li>
<p>java.lang.Long</p>
</li>
<li>
<p>java.lang.Short</p>
</li>
<li>
<p>java.lang.Character</p>
</li>
<li>
<p>java.lang.Byte</p>
</li>
<li>
<p>java.lang.Boolean</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>That being said, Jetty is a little more flexible and allows you to also bind custom POJOs, <a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/naming/Reference.html"><code>javax.naming.References</code></a> and <a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/naming/Referenceable.html"><code>javax.naming.Referenceables</code></a>.
Be aware that if you take advantage of this feature, your web application is <em>not portable</em>.</p>
</div>
<div class="paragraph">
<p>To use the <code>env-entry</code> configured above, use code in your <code>servlet/filter/etc.</code>, such as:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">javax.naming.InitialContext</span>;
<span class="directive">public</span> <span class="type">class</span> <span class="class">MyClass</span> {
<span class="directive">public</span> <span class="type">void</span> myMethod() {
<span class="predefined-type">InitialContext</span> ic = <span class="keyword">new</span> <span class="predefined-type">InitialContext</span>();
<span class="predefined-type">Integer</span> mySpecialValue = (<span class="predefined-type">Integer</span>)ic.lookup(<span class="string"><span class="delimiter">&quot;</span><span class="content">java:comp/env/mySpecialValue</span><span class="delimiter">&quot;</span></span>);
...
}
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="configuring-resource-refs-and-resource-env-refs"><a class="anchor" href="#configuring-resource-refs-and-resource-env-refs"></a><a class="link" href="#configuring-resource-refs-and-resource-env-refs">Configuring <em>resource-refs</em> and <em>resource-env-refs</em></a></h4>
<div class="paragraph">
<p>You can configure any type of resource that you want to refer to in a <code>web.xml</code> file as a <code>resource-ref</code> or <code>resource-env-ref</code>, using the <code>org.eclipse.jetty.plus.jndi.Resource</code> type of naming entry.
You provide the scope, the name of the object (relative to <code>java:comp/env</code>) and a POJO instance or a <code>javax.naming.Reference</code> instance or <code>javax.naming.Referenceable</code> instance.</p>
</div>
<div class="paragraph">
<p>The <a href="http://jcp.org/aboutJava/communityprocess/pr/jsr244/index.html">J2EE Specification</a> recommends storing DataSources in <code>java:comp/env/jdbc</code>, JMS connection factories under <code>java:comp/env/jms</code>, JavaMail connection factories under <code>java:comp/env/mail</code> and URL connection factories under <code>java:comp/env/url</code>.</p>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 19. DataSource Declaration Conventions</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Resource Type</th>
<th class="tableblock halign-left valign-top">Name in <code>jetty.xml</code></th>
<th class="tableblock halign-left valign-top">Environment Lookup</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">javax.sql.DataSource</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">jdbc/myDB</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">java:comp/env/jdbc/myDB</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">javax.jms.QueueConnectionFactory</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">jms/myQueue</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">java:comp/env/jms/myQueue</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">javax.mail.Session</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">mail/myMailService</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">java:comp/env/mail/myMailService</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect3">
<h4 id="configuring-datasources"><a class="anchor" href="#configuring-datasources"></a><a class="link" href="#configuring-datasources">Configuring DataSources</a></h4>
<div class="paragraph">
<p>Here is an example of configuring a <code>javax.sql.DataSource</code>.
Jetty can use any DataSource implementation available on its classpath.
In this example, the DataSource is from the <a href="http://db.apache.org/derby">Derby</a> relational database, but you can use any implementation of a <code>javax.sql.DataSource</code>.
This example configures it as scoped to a web app with the id of <em>wac</em>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">'</span><span class="content">wac</span><span class="delimiter">'</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myds</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">wac</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/myds<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.apache.derby.jdbc.EmbeddedDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DatabaseName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>test<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">createDatabase</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>create<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The code above creates an instance of <code>org.apache.derby.jdbc.EmbeddedDataSource</code>, calls the two setter methods <code>setDatabaseName("test"),</code> and <code>setCreateDatabase("create"),</code> and binds it into the JNDI scope for the web app.
If you do not have the appropriate <code>resource-ref</code> set up in your <code>web.xml</code>, it is available from application lookups as <code>java:comp/env/jdbc/myds</code>.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example <code>web.xml</code> declaration for the datasource above:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;resource-ref&gt;</span>
<span class="tag">&lt;res-ref-name&gt;</span>jdbc/myds<span class="tag">&lt;/res-ref-name&gt;</span>
<span class="tag">&lt;res-type&gt;</span>javax.sql.DataSource<span class="tag">&lt;/res-type&gt;</span>
<span class="tag">&lt;res-auth&gt;</span>Container<span class="tag">&lt;/res-auth&gt;</span>
<span class="tag">&lt;/resource-ref&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>To look up your DataSource in your <code>servlet/filter/etc.</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">javax.naming.InitialContext</span>;
<span class="keyword">import</span> <span class="include">javax.sql.DataSource</span>;
<span class="directive">public</span> <span class="type">class</span> <span class="class">MyClass</span> {
<span class="directive">public</span> <span class="type">void</span> myMethod() {
<span class="predefined-type">InitialContext</span> ic = <span class="keyword">new</span> <span class="predefined-type">InitialContext</span>();
<span class="predefined-type">DataSource</span> myDS = (<span class="predefined-type">DataSource</span>)ic.lookup(<span class="string"><span class="delimiter">&quot;</span><span class="content">java:comp/env/jdbc/myds</span><span class="delimiter">&quot;</span></span>);
...
}
}</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Careful! When configuring Resources, ensure that the type of object you configure matches the type of object you expect to look up in <code>java:comp/env</code>.
For database connection factories, this means that the object you register as a Resource <em>must</em> implement the <code>javax.sql.DataSource</code> interface.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>For more examples of datasource configurations, see <a href="#jndi-datasource-examples">Datasource Examples</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="configuring-jms-queues-topics-connectionfactories"><a class="anchor" href="#configuring-jms-queues-topics-connectionfactories"></a><a class="link" href="#configuring-jms-queues-topics-connectionfactories">Configuring JMS Queues, Topics and ConnectionFactories</a></h4>
<div class="paragraph">
<p>Jetty can bind any implementation of the JMS destinations and connection factories.
You just need to ensure the implementation Jars are available on Jetty&#8217;s classpath.
Here is an example of binding an <a href="http://activemq.apache.org">ActiveMQ</a> in-JVM connection factory:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">'</span><span class="content">wac</span><span class="delimiter">'</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">cf</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">'</span><span class="content">wac</span><span class="delimiter">'</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jms/connectionFactory<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.apache.activemq.ActiveMQConnectionFactory</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>vm://localhost?broker.persistent=false<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The entry in <code>web.xml</code> would be:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;resource-ref&gt;</span>
<span class="tag">&lt;res-ref-name&gt;</span>jms/connectionFactory<span class="tag">&lt;/res-ref-name&gt;</span>
<span class="tag">&lt;res-type&gt;</span>javax.jms.ConnectionFactory<span class="tag">&lt;/res-type&gt;</span>
<span class="tag">&lt;res-auth&gt;</span>Container<span class="tag">&lt;/res-auth&gt;</span>
<span class="tag">&lt;/resource-ref&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="configuring-mail-with-jndi"><a class="anchor" href="#configuring-mail-with-jndi"></a><a class="link" href="#configuring-mail-with-jndi">Configuring Mail</a></h4>
<div class="paragraph">
<p>Jetty also provides infrastructure for access to <code>javax.mail.Sessions</code> from within an application:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">'</span><span class="content">wac</span><span class="delimiter">'</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">mail</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">wac</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>mail/Session<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.jndi.factories.MailSessionReference</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">user</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>fred<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>OBF:1xmk1w261z0f1w1c1xmq<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">properties</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.util.Properties</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Put</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">mail.smtp.host</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>XXX<span class="tag">&lt;/Put&gt;</span>
<span class="tag">&lt;Put</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">mail.from</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>me@me<span class="tag">&lt;/Put&gt;</span>
<span class="tag">&lt;Put</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">mail.debug</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Put&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This setup creates an instance of the <code>org.eclipse.jetty.jndi.factories.MailSessionReference</code> class, calls it&#8217;s setter methods to set up the authentication for the mail system, and populates a set of Properties, setting them on the <code>MailSessionReference</code> instance.
The result is that an application can look up <code>java:comp/env/mail/Session</code> at runtime and obtain access to a <code>javax.mail.Session</code> that has the necessary configuration to permit it to send email via SMTP.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
As of Jetty 10, the <a href="http://central.maven.org/maven2/org/eclipse/jetty/orbit/javax.mail.glassfish/1.4.1.v201005082020/javax.mail.glassfish-1.4.1.v201005082020.jar"><code>javax.mail</code></a> and <a href="http://central.maven.org/maven2/org/eclipse/jetty/orbit/javax.activation/1.1.0.v201105071233/javax.activation-1.1.0.v201105071233.jar"><code>javax.activation</code></a> jar files are not included in the Jetty Distribution and will need to be downloaded separately from Maven Central.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
You can set the password to be plain text, or use Jetty&#8217;s <a href="#configuring-security-secure-passwords">Secure Password Obfuscation</a> (OBF:) mechanism to make the config file a little more secure from prying eyes.
Remember that you cannot use the other Jetty encryption mechanisms of MD5 and Crypt because they do not allow you to recover the original password, which the mail system requires.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="configuring-xa-transactions"><a class="anchor" href="#configuring-xa-transactions"></a><a class="link" href="#configuring-xa-transactions">Configuring XA Transactions</a></h4>
<div class="paragraph">
<p>If you want to perform distributed transactions with your resources, you need a <em>transaction manager</em> that supports the JTA interfaces, and that you can look up as <code>java:comp/UserTransaction</code> in your webapp.
Jetty does not ship with one as standard, but you can plug in the one you prefer.
You can configure a transaction manager using the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/plus/jndi/Transaction.html">JNDI Transaction</a> object in a Jetty config file.
The following example configures the <a href="http://www.atomikos.com/">Atomikos</a> transaction manager:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">tx</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Transaction</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.atomikos.icatch.jta.J2eeUserTransaction</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="configuring-links"><a class="anchor" href="#configuring-links"></a><a class="link" href="#configuring-links">Configuring Links</a></h4>
<div class="paragraph">
<p>Generally, the name you set for your <code>Resource</code> should be the same name you use for it in <code>web.xml</code>.
For example:</p>
</div>
<div class="paragraph">
<p>In a context xml file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">'</span><span class="content">wac</span><span class="delimiter">'</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myds</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">wac</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/mydatasource<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.apache.derby.jdbc.EmbeddedDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DatabaseName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>test<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">createDatabase</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>create<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>In a <code>web.xml</code> file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;resource-ref&gt;</span>
<span class="tag">&lt;res-ref-name&gt;</span>jdbc/mydatasource<span class="tag">&lt;/res-ref-name&gt;</span>
<span class="tag">&lt;res-type&gt;</span>javax.sql.DataSource<span class="tag">&lt;/res-type&gt;</span>
<span class="tag">&lt;res-auth&gt;</span>Container<span class="tag">&lt;/res-auth&gt;</span>
<span class="tag">&lt;injection-target&gt;</span>
<span class="tag">&lt;injection-target-class&gt;</span>com.acme.JNDITest<span class="tag">&lt;/injection-target-class&gt;</span>
<span class="tag">&lt;injection-target-name&gt;</span>myDatasource<span class="tag">&lt;/injection-target-name&gt;</span>
<span class="tag">&lt;/injection-target&gt;</span>
<span class="tag">&lt;/resource-ref&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>However, you can refer to it in <code>web.xml</code> by a different name, and link it to the name in your <code>org.eclipse.jetty.plus.jndi.Resource</code> by using an <code>org.eclipse.jetty.plus.jndi.Link</code>.
For the example above, you can refer to the <code>jdbc/mydatasource</code> resource as <code>jdbc/mydatasource1</code> as follows:</p>
</div>
<div class="paragraph">
<p>In a context xml file declare <code>jdbc/mydatasource</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">'</span><span class="content">wac</span><span class="delimiter">'</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myds</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">wac</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/mydatasource<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.apache.derby.jdbc.EmbeddedDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DatabaseName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>test<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">createDatabase</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>create<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Then in a <code>WEB-INF/jetty-env.xml</code> file, link the name <code>jdbc/mydatasource</code> to the name you want to reference it as in
<code>web.xml</code>, which in this case is <code>jdbc/mydatasource1</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">map1</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Link</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">'</span><span class="content">wac</span><span class="delimiter">'</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/mydatasource1<span class="tag">&lt;/Arg&gt;</span> <span class="comment">&lt;!-- name in web.xml --&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/mydatasource<span class="tag">&lt;/Arg&gt;</span> <span class="comment">&lt;!-- name in container environment --&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Now you can refer to <code>jdbc/mydatasource1</code> in the <code>web.xml</code> like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;resource-ref&gt;</span>
<span class="tag">&lt;res-ref-name&gt;</span>jdbc/mydatasource1<span class="tag">&lt;/res-ref-name&gt;</span>
<span class="tag">&lt;res-type&gt;</span>javax.sql.DataSource<span class="tag">&lt;/res-type&gt;</span>
<span class="tag">&lt;res-auth&gt;</span>Container<span class="tag">&lt;/res-auth&gt;</span>
<span class="tag">&lt;injection-target&gt;</span>
<span class="tag">&lt;injection-target-class&gt;</span>com.acme.JNDITest<span class="tag">&lt;/injection-target-class&gt;</span>
<span class="tag">&lt;injection-target-name&gt;</span>myDatasource<span class="tag">&lt;/injection-target-name&gt;</span>
<span class="tag">&lt;/injection-target&gt;</span>
<span class="tag">&lt;/resource-ref&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This can be useful when you cannot change a JNDI resource directly in the <code>web.xml</code> but need to link it to a specific resource in your deployment environment.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="jndi-embedded"><a class="anchor" href="#jndi-embedded"></a><a class="link" href="#jndi-embedded">Using JNDI with Jetty Embedded</a></h3>
<div class="sect3">
<h4 id="_setting-up-the-classpath-2"><a class="anchor" href="#_setting-up-the-classpath-2"></a><a class="link" href="#_setting-up-the-classpath-2">Setting up the Classpath</a></h4>
<div class="paragraph">
<p>In addition to the jars that you require for your application, and the jars needed for core Jetty, you will need to place the following jars onto your classpath:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>jetty-jndi.jar
jetty-plus.jar</pre>
</div>
</div>
<div class="paragraph">
<p>If you are using transactions, you will also need the <code>javax.transaction</code> api.
You can obtain this jar <a href="http://central.maven.org/maven2/org/eclipse/jetty/orbit/javax.transaction/1.1.1.v201105210645/javax.transaction-1.1.1.v201105210645.jar">here.</a></p>
</div>
<div class="paragraph">
<p>If you wish to use mail, you will also need the <code>javax.mail</code> api and implementation which <a href="http://central.maven.org/maven2/org/eclipse/jetty/orbit/javax.mail.glassfish/1.4.1.v201005082020/javax.mail.glassfish-1.4.1.v201005082020.jar">you can download here.</a>
Note that this jar also requires the <code>javax.activation</code> classes, which is available <a href="http://central.maven.org/maven2/org/eclipse/jetty/orbit/javax.activation/1.1.0.v201105071233/javax.activation-1.1.0.v201105071233.jar">at this link.</a></p>
</div>
</div>
<div class="sect3">
<h4 id="_example-code"><a class="anchor" href="#_example-code"></a><a class="link" href="#_example-code">Example Code</a></h4>
<div class="paragraph">
<p>Here is an example class that sets up some JNDI entries and deploys a webapp that references these JNDI entries in code.
We&#8217;ll use some mocked up classes for the transaction manager and the DataSource in this example for simplicity:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">java.util.Properties</span>;
<span class="keyword">import</span> <span class="include">org.eclipse.jetty.server.Server</span>;
<span class="keyword">import</span> <span class="include">org.eclipse.jetty.webapp.WebAppContext</span>;
<span class="comment">/**
* ServerWithJNDI
*
*
*/</span>
<span class="directive">public</span> <span class="type">class</span> <span class="class">ServerWithJNDI</span>
{
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> main(<span class="predefined-type">String</span><span class="type">[]</span> args) <span class="directive">throws</span> <span class="exception">Exception</span>
{
<span class="comment">//Create the server</span>
Server server = <span class="keyword">new</span> Server(<span class="integer">8080</span>);
<span class="comment">//Enable parsing of jndi-related parts of web.xml and jetty-env.xml</span>
org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addAfter(<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.FragmentConfiguration</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.webapp.EnvConfiguration</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.webapp.PlusConfiguration</span><span class="delimiter">&quot;</span></span>);
<span class="comment">//Create a WebApp</span>
WebAppContext webapp = <span class="keyword">new</span> WebAppContext();
webapp.setContextPath(<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span>);
webapp.setWar(<span class="string"><span class="delimiter">&quot;</span><span class="content">./my-foo-webapp.war</span><span class="delimiter">&quot;</span></span>);
server.setHandler(webapp);
<span class="comment">//Register new transaction manager in JNDI</span>
<span class="comment">//At runtime, the webapp accesses this as java:comp/UserTransaction</span>
org.eclipse.jetty.plus.jndi.Transaction transactionMgr = <span class="keyword">new</span> org.eclipse.jetty.plus.jndi.Transaction(<span class="keyword">new</span> com.acme.MockUserTransaction());
<span class="comment">//Define an env entry with Server scope.</span>
<span class="comment">//At runtime, the webapp accesses this as java:comp/env/woggle</span>
<span class="comment">//This is equivalent to putting an env-entry in web.xml:</span>
<span class="comment">//&lt;env-entry&gt;</span>
<span class="comment">// &lt;env-entry-name&gt;woggle&lt;/env-entry-name&gt;</span>
<span class="comment">// &lt;env-entry-type&gt;java.lang.Integer&lt;/env-entry-type&gt;</span>
<span class="comment">// &lt;env-entry-value&gt;4000&lt;/env-entry-value&gt;</span>
<span class="comment">//&lt;/env-entry&gt;</span>
org.eclipse.jetty.plus.jndi.EnvEntry woggle = <span class="keyword">new</span> org.eclipse.jetty.plus.jndi.EnvEntry(server, <span class="string"><span class="delimiter">&quot;</span><span class="content">woggle</span><span class="delimiter">&quot;</span></span>, <span class="keyword">new</span> <span class="predefined-type">Integer</span>(<span class="integer">4000</span>), <span class="predefined-constant">false</span>);
<span class="comment">//Define an env entry with webapp scope.</span>
<span class="comment">//At runtime, the webapp accesses this as java:comp/env/wiggle</span>
<span class="comment">//This is equivalent to putting a web.xml entry in web.xml:</span>
<span class="comment">//&lt;env-entry&gt;</span>
<span class="comment">// &lt;env-entry-name&gt;wiggle&lt;/env-entry-name&gt;</span>
<span class="comment">// &lt;env-entry-value&gt;100&lt;/env-entry-value&gt;</span>
<span class="comment">// &lt;env-entry-type&gt;java.lang.Double&lt;/env-entry-type&gt;</span>
<span class="comment">//&lt;/env-entry&gt;</span>
<span class="comment">//Note that the last arg of &quot;true&quot; means that this definition for &quot;wiggle&quot; would override an entry of the</span>
<span class="comment">//same name in web.xml</span>
org.eclipse.jetty.plus.jndi.EnvEntry wiggle = <span class="keyword">new</span> org.eclipse.jetty.plus.jndi.EnvEntry(webapp, <span class="string"><span class="delimiter">&quot;</span><span class="content">wiggle</span><span class="delimiter">&quot;</span></span>, <span class="keyword">new</span> <span class="predefined-type">Double</span>(<span class="integer">100</span>), <span class="predefined-constant">true</span>);
<span class="comment">//Register a reference to a mail service scoped to the webapp.</span>
<span class="comment">//This must be linked to the webapp by an entry in web.xml:</span>
<span class="comment">// &lt;resource-ref&gt;</span>
<span class="comment">// &lt;res-ref-name&gt;mail/Session&lt;/res-ref-name&gt;</span>
<span class="comment">// &lt;res-type&gt;javax.mail.Session&lt;/res-type&gt;</span>
<span class="comment">// &lt;res-auth&gt;Container&lt;/res-auth&gt;</span>
<span class="comment">// &lt;/resource-ref&gt;</span>
<span class="comment">//At runtime the webapp accesses this as java:comp/env/mail/Session</span>
org.eclipse.jetty.jndi.factories.MailSessionReference mailref = <span class="keyword">new</span> org.eclipse.jetty.jndi.factories.MailSessionReference();
mailref.setUser(<span class="string"><span class="delimiter">&quot;</span><span class="content">CHANGE-ME</span><span class="delimiter">&quot;</span></span>);
mailref.setPassword(<span class="string"><span class="delimiter">&quot;</span><span class="content">CHANGE-ME</span><span class="delimiter">&quot;</span></span>);
<span class="predefined-type">Properties</span> props = <span class="keyword">new</span> <span class="predefined-type">Properties</span>();
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">mail.smtp.auth</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">false</span><span class="delimiter">&quot;</span></span>);
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">mail.smtp.host</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">CHANGE-ME</span><span class="delimiter">&quot;</span></span>);
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">mail.from</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">CHANGE-ME</span><span class="delimiter">&quot;</span></span>);
props.put(<span class="string"><span class="delimiter">&quot;</span><span class="content">mail.debug</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">false</span><span class="delimiter">&quot;</span></span>);
mailref.setProperties(props);
org.eclipse.jetty.plus.jndi.Resource xxxmail = <span class="keyword">new</span> org.eclipse.jetty.plus.jndi.Resource(webapp, <span class="string"><span class="delimiter">&quot;</span><span class="content">mail/Session</span><span class="delimiter">&quot;</span></span>, mailref);
<span class="comment">// Register a mock DataSource scoped to the webapp</span>
<span class="comment">//This must be linked to the webapp via an entry in web.xml:</span>
<span class="comment">//&lt;resource-ref&gt;</span>
<span class="comment">// &lt;res-ref-name&gt;jdbc/mydatasource&lt;/res-ref-name&gt;</span>
<span class="comment">// &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;</span>
<span class="comment">// &lt;res-auth&gt;Container&lt;/res-auth&gt;</span>
<span class="comment">//&lt;/resource-ref&gt;</span>
<span class="comment">//At runtime the webapp accesses this as java:comp/env/jdbc/mydatasource</span>
org.eclipse.jetty.plus.jndi.Resource mydatasource = <span class="keyword">new</span> org.eclipse.jetty.plus.jndi.Resource(webapp, <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc/mydatasource</span><span class="delimiter">&quot;</span></span>,
<span class="keyword">new</span> com.acme.MockDataSource());
server.start();
server.join();
}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="jndi-datasource-examples"><a class="anchor" href="#jndi-datasource-examples"></a><a class="link" href="#jndi-datasource-examples">Datasource Examples</a></h3>
<div class="paragraph">
<p>Here are examples of configuring a JNDI datasource for various databases.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Read <a href="#configuring-datasources">Configuring DataSources</a> in <a href="#jndi-configuration">Configuring JNDI</a> for more information about configuring datasources.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>All of these examples correspond to a <code>resource-ref</code> in <code>web.xml</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;resource-ref&gt;</span>
<span class="tag">&lt;description&gt;</span>My DataSource Reference<span class="tag">&lt;/description&gt;</span>
<span class="tag">&lt;res-ref-name&gt;</span>jdbc/DSTest<span class="tag">&lt;/res-ref-name&gt;</span>
<span class="tag">&lt;res-type&gt;</span>javax.sql.DataSource<span class="tag">&lt;/res-type&gt;</span>
<span class="tag">&lt;res-auth&gt;</span>Container<span class="tag">&lt;/res-auth&gt;</span>
<span class="tag">&lt;/resource-ref&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>These examples assume that all of the datasources are declared at the JVM scope, but you can use other scopes if desired.
You can configure all JNDI resources in a <code>jetty.xml</code> file, a <code>WEB-INF/jetty-env.xml</code> file, or a context XML file.
See the section <a href="#jndi-where-to-declare">Deciding Where to Declare Resources</a> for more information.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
You must provide Jetty with the libraries necessary to instantiate the datasource you have configured by putting the corresponding Jar in <code>JETTY_HOME/lib/ext</code>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect3">
<h4 id="pooling-datasources"><a class="anchor" href="#pooling-datasources"></a><a class="link" href="#pooling-datasources">Pooling DataSources</a></h4>
<div class="paragraph">
<p>Pooling datasources enables connection pooling, which lets you reuse an existing connection instead of creating a new connection to the database.
This is highly efficient in terms of memory allocation and speed of the request to the database.
We highly recommend this option for production environments.</p>
</div>
<div class="paragraph">
<p>The following is a list of the pooled datasource examples we have worked with in the past:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#hikaricp-datasource">HikariCP</a></p>
</li>
<li>
<p><a href="#bonecp-datasource">BoneCP</a></p>
</li>
<li>
<p><a href="#c3p0-datasource">c3p0</a></p>
</li>
<li>
<p><a href="#dbcp-datasource">DBCP</a></p>
</li>
<li>
<p><a href="#atomikos-datasource">Atomikos 3.3.2+</a></p>
</li>
<li>
<p><a href="#mysql-pooled-datasource">MySQL</a></p>
</li>
<li>
<p><a href="#postgreSQL-pooled-datasource">PostgreSQL</a></p>
</li>
<li>
<p><a href="#DB2-pooled-datasource">DB2</a></p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="hikaricp-datasource"><a class="anchor" href="#hikaricp-datasource"></a><a class="link" href="#hikaricp-datasource">HikariCP</a></h5>
<div class="paragraph">
<p>Connection pooling, available at <a href="http://search.maven.org/remotecontent?filepath=com/zaxxer/HikariCP/1.4.0/HikariCP-1.4.0.jar">HikariCP Download</a>.
All configuration options for HikariCP are described here: <a href="https://github.com/brettwooldridge/HikariCP">HikariCP documentation</a>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.zaxxer.hikari.HikariDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.zaxxer.hikari.HikariConfig</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">minimumPoolSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>5<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">maximumPoolSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>20<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">dataSourceClassName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>com.mysql.jdbc.jdbc2.optional.MysqlDataSource<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">username</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addDataSourceProperty</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>url<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc.url<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="bonecp-datasource"><a class="anchor" href="#bonecp-datasource"></a><a class="link" href="#bonecp-datasource">BoneCP</a></h5>
<div class="paragraph">
<p>Connection pooling, available at <a href="http://jolbox.com/index.html?page=http://jolbox.com/download.html">BoneCP Download</a>.
All configuration options for BoneCP are described here: <a href="http://jolbox.com/bonecp/downloads/site/apidocs/com/jolbox/bonecp/BoneCPDataSource.html">BoneCP API</a>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.jolbox.bonecp.BoneCPDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">driverClass</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>com.mysql.jdbc.Driver<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jdbcUrl</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.url<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">username</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">minConnectionsPerPartition</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>5<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">maxConnectionsPerPartition</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>50<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">acquireIncrement</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>5<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">idleConnectionTestPeriod</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>30<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="c3p0-datasource"><a class="anchor" href="#c3p0-datasource"></a><a class="link" href="#c3p0-datasource">c3p0</a></h5>
<div class="paragraph">
<p>Connection pooling, available at <a href="https://repo1.maven.org/maven2/c3p0/c3p0/0.9.1.2/c3p0-0.9.1.2.jar">c3p0 Jar</a>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.mchange.v2.c3p0.ComboPooledDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">driverClass</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>org.some.Driver<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jdbcUrl</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.url<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">user</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="dbcp-datasource"><a class="anchor" href="#dbcp-datasource"></a><a class="link" href="#dbcp-datasource">DBCP</a></h5>
<div class="paragraph">
<p>Connection pooling, available at <a href="https://repo1.maven.org/maven2/commons-dbcp/commons-dbcp/1.2/commons-dbcp-1.2.jar">dbcp Jar</a>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.apache.commons.dbcp.BasicDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">driverClassName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>org.some.Driver<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">url</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.url<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">username</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc.pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="atomikos-datasource"><a class="anchor" href="#atomikos-datasource"></a><a class="link" href="#atomikos-datasource">Atomikos 3.3.2+</a></h5>
<div class="paragraph">
<p>Connection pooling + XA transactions.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.atomikos.jdbc.AtomikosDataSourceBean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">minPoolSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>2<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">maxPoolSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>50<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">xaDataSourceClassName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">UniqueResourceName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>DSTest<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Get</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">xaProperties</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setProperty</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>url<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc:mysql://localhost:3306/databasename<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setProperty</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>user<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>some_username<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setProperty</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>password<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>some_password<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Get&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="mysql-pooled-datasource"><a class="anchor" href="#mysql-pooled-datasource"></a><a class="link" href="#mysql-pooled-datasource">MySQL</a></h5>
<div class="paragraph">
<p>Implements <code>javax.sql.DataSource</code> and <code>javax.sql.ConnectionPoolDataSource</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Url</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc:mysql://localhost:3306/databasename<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">User</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="postgreSQL-pooled-datasource"><a class="anchor" href="#postgreSQL-pooled-datasource"></a><a class="link" href="#postgreSQL-pooled-datasource">PostgreSQL</a></h5>
<div class="paragraph">
<p>Implements <code>javax.sql.ConnectionPoolDataSource</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.postgresql.ds.PGConnectionPoolDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">User</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DatabaseName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>dbname<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">ServerName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>localhost<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">PortNumber</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>5432<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="DB2-pooled-datasource"><a class="anchor" href="#DB2-pooled-datasource"></a><a class="link" href="#DB2-pooled-datasource">DB2</a></h5>
<div class="paragraph">
<p>Implements <code>javax.sql.ConnectionPoolDataSource</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.ibm.db2.jcc.DB2ConnectionPoolDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DatabaseName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>dbname<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">User</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">ServerName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>servername<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">PortNumber</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>50000<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="non-pooling-datasources"><a class="anchor" href="#non-pooling-datasources"></a><a class="link" href="#non-pooling-datasources">Non-pooling DataSources</a></h4>
<div class="paragraph">
<p>If you are deploying in a production environment, we highly recommend using a Pooling DataSource.
Since that is not always an option we have a handful of examples for non-pooling datasources listed here as well.</p>
</div>
<div class="paragraph">
<p>The following is a list of the non-pooled datasource examples:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#sql-server-2000-datasource">SQL Server 2000</a></p>
</li>
<li>
<p><a href="#oracle-9i10g-datasource">Oracle 9i/10g</a></p>
</li>
<li>
<p><a href="#postgreSQL-datasource">PostgreSQL</a></p>
</li>
<li>
<p><a href="#sybase-datasource">Sybase</a></p>
</li>
<li>
<p><a href="#DB2-datasource">DB2</a></p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="sql-server-2000-datasource"><a class="anchor" href="#sql-server-2000-datasource"></a><a class="link" href="#sql-server-2000-datasource">SQL Server 2000</a></h5>
<div class="paragraph">
<p>Implements <code>javax.sql.DataSource</code> and <code>javax.sql.ConnectionPoolDataSource</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">net.sourceforge.jtds.jdbcx.JtdsDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">User</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DatabaseName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>dbname<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">ServerName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>localhost<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">PortNumber</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>1433<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="oracle-9i10g-datasource"><a class="anchor" href="#oracle-9i10g-datasource"></a><a class="link" href="#oracle-9i10g-datasource">Oracle 9i/10g</a></h5>
<div class="paragraph">
<p>Implements <code>javax.sql.DataSource</code> and <code>javax.sql.ConnectionPoolDataSource</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">oracle.jdbc.pool.OracleDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DriverType</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>thin<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">URL</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc:oracle:thin:@fmsswdb1:10017:otcd<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">User</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>xxxx<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>xxxx<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">connectionCachingEnabled</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">connectionCacheProperties</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.util.Properties</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setProperty</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>MinLimit<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>5<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="comment">&lt;!-- put the other properties in here too --&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>For more information, refer to: <a href="http://docs.oracle.com/cd/B14117_01/java.101/b10979/conncache.htm">Oracle Database JDBC documentation</a>.</p>
</div>
</div>
<div class="sect4">
<h5 id="postgreSQL-datasource"><a class="anchor" href="#postgreSQL-datasource"></a><a class="link" href="#postgreSQL-datasource">PostgreSQL</a></h5>
<div class="paragraph">
<p>Implements <code>javax.sql.DataSource</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.postgresql.ds.PGSimpleDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">User</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DatabaseName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>dbname<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">ServerName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>localhost<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">PortNumber</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>5432<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="sybase-datasource"><a class="anchor" href="#sybase-datasource"></a><a class="link" href="#sybase-datasource">Sybase</a></h5>
<div class="paragraph">
<p>Implements <code>javax.sql.DataSource</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.sybase.jdbc2.jdbc.SybDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DatabaseName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>dbname<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">User</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">ServerName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>servername<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">PortNumber</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>5000<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="DB2-datasource"><a class="anchor" href="#DB2-datasource"></a><a class="link" href="#DB2-datasource">DB2</a></h5>
<div class="paragraph">
<p>Implements <code>javax.sql.DataSource</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.ibm.db2.jcc.DB2SimpleDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DatabaseName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>dbname<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">User</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>user<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>pass<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">ServerName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>servername<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">PortNumber</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>50000<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="configuring-jsp"><a class="anchor" href="#configuring-jsp"></a><a class="link" href="#configuring-jsp">Configuring JSP Support</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="jsp-support"><a class="anchor" href="#jsp-support"></a><a class="link" href="#jsp-support">Configuring JSP</a></h3>
<div class="paragraph">
<p>This document provides information about configuring Java Server Pages (JSP) for Jetty.</p>
</div>
<div class="sect3">
<h4 id="which-jsp-implementation"><a class="anchor" href="#which-jsp-implementation"></a><a class="link" href="#which-jsp-implementation">Which JSP Implementation</a></h4>
<div class="paragraph">
<p>Jetty uses Jasper from <a href="http://tomcat.apache.org/tomcat-8.0-doc/jasper-howto.html">Apache</a> as the default JSP container implementation.</p>
</div>
<div class="paragraph">
<p>By default the Jetty distribution enables the JSP <a href="#startup-modules">module</a>, and by default, this module is set to Apache Jasper.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Unresolved directive in jsp/configuring-jsp.adoc - include::/home/joakim/code/jetty/jetty.project-10.0.x/documentation/jetty-documentation/../jetty-home/src/main/resources/modules/jsp.mod[]</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that the availability of some JSP features may depend on which JSP container implementation you are using.
Note also that it may not be possible to precompile your JSPs with one container and deploy to the other.</p>
</div>
<div class="sect4">
<h5 id="_logging"><a class="anchor" href="#_logging"></a><a class="link" href="#_logging">Logging</a></h5>
<div class="paragraph">
<p>The Apache Jasper logging system is bridged to the jetty logging system.
Thus, you can enable logging for jsps in the same way you have setup for your webapp.
For example, assuming you are using Jetty&#8217;s default StdErr logger, you would enable DEBUG level logging for jsps by adding the system property <code>-Dorg.apache.jasper.LEVEL=DEBUG</code> to the command line.</p>
</div>
</div>
<div class="sect4">
<h5 id="_jsps-and-embedding"><a class="anchor" href="#_jsps-and-embedding"></a><a class="link" href="#_jsps-and-embedding">JSPs and Embedding</a></h5>
<div class="paragraph">
<p>If you have an embedded setup for your webapp and wish to use JSPs, you will need to ensure that a JSP engine is correctly initialized.</p>
</div>
<div class="paragraph">
<p>For Apache, a Servlet Specification 3.1 style <a href="#servlet-container-initializers">ServletContainerInitializer</a> is used to accomplish this.
You will need to ensure that this ServletContainerInitializer is run by jetty. Perhaps the easiest way to do this is to enable annotations processing so that Jetty automatically discovers and runs it.
The <a href="#embedded-examples">Embedded Examples</a> section includes a <a href="#embedded-webapp-jsp">worked code example</a> of how to do this.</p>
</div>
<div class="paragraph">
<p>Alternatively, you can manually wire in the appropriate ServletContainerInitializer as shown in the <a href="https://github.com/jetty-project/embedded-jetty-jsp/blob/master/src/main/java/org/eclipse/jetty/demo/Main.java">embedded-jetty-jsp</a> example on <a href="https://github.com/jetty-project">GitHub</a>, in which case you will not need the jetty-annotations jar on your classpath, nor include the AnnotationConfiguration in the list of <a href="#webapp-configurations">configuration classes</a>.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_precompiling-jsps"><a class="anchor" href="#_precompiling-jsps"></a><a class="link" href="#_precompiling-jsps">Precompiling JSPs</a></h4>
<div class="paragraph">
<p>You can either follow the instructions on precompilation provided by Apache, or if you are using Maven for your builds, you can use the <a href="#jetty-jspc-maven-plugin">jetty-jspc-maven</a> plugin to do it for you.</p>
</div>
<div class="paragraph">
<p>If you have precompiled your JSPs, and have customized the output package prefix (which is <code>org.apache.jsp</code> by default), you should configure your webapp context to tell Jetty about this custom package name.
You can do this using a servlet context init-param called <code>org.eclipse.jetty.servlet.jspPackagePrefix</code>.</p>
</div>
<div class="paragraph">
<p>For example, suppose you have precompiled your JSPs with the custom package prefix of <code>com.acme</code>, then you would add the following lines to your <code>web.xml</code> file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;context-param&gt;</span>
<span class="tag">&lt;param-name&gt;</span>org.eclipse.jetty.servlet.jspPackagePrefix<span class="tag">&lt;/param-name&gt;</span>
<span class="tag">&lt;param-value&gt;</span>com.acme<span class="tag">&lt;/param-value&gt;</span>
<span class="tag">&lt;/context-param&gt;</span></code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Both Jetty Maven plugins - <a href="#jetty-jspc-maven-plugin">jetty-jspc-maven-plugin</a> and the <a href="#jetty-maven-plugin">jetty-maven-plugin</a> - will only use Apache Jasper.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect4">
<h5 id="compiling-jsps"><a class="anchor" href="#compiling-jsps"></a><a class="link" href="#compiling-jsps">Apache JSP Container</a></h5>
<div class="paragraph">
<p>By default, the Apache JSP container will look for the Eclipse Java Compiler (jdt).
The Jetty distribution ships a copy of this in <code>{$jetty.home}/lib/apache-jsp</code>.
If you wish to use a different compiler, you will need to configure the <code>compilerClassName</code> init-param on the <code>JspServlet</code> with the name of the class.</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 20. Understanding Apache JspServlet Parameters</caption>
<colgroup>
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">init param</th>
<th class="tableblock halign-left valign-top">Description</th>
<th class="tableblock halign-left valign-top">Default</th>
<th class="tableblock halign-left valign-top"><code>webdefault.xml</code></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">checkInterval</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If non-zero and <code>development</code> is <code>false</code>, background jsp recompilation is enabled. This value is the interval in seconds between background recompile checks.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">classpath</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The classpath is dynamically generated if the context has a URL classloader. The <code>org.apache.catalina.jsp_classpath</code>
context attribute is used to add to the classpath, but if this is not set, this <code>classpath</code> configuration item is added to the classpath instead.`</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">classdebuginfo</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Include debugging info in class file.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">compilerClassName</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If not set, defaults to the Eclipse jdt compiler.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">compiler</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Used if the Eclipse jdt compiler cannot be found on the
classpath. It is the classname of a compiler that Ant should invoke.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">compilerTargetVM</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Target vm to compile for.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.8</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.8</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">compilerSourceVM</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Sets source compliance level for the jdt compiler.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.8</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.8</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">development</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If <code>true</code> recompilation checks occur at the frequency governed by <code>modificationTestInterval</code>.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">displaySourceFragment</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Should a source fragment be included in
exception messages</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">dumpSmap</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Dump SMAP JSR45 info to a file.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">enablePooling</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Determines whether tag handler pooling is enabled.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">engineOptionsClass</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Allows specifying the Options class used to
configure Jasper. If not present, the default EmbeddedServletOptions
will be used.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">errorOnUseBeanInvalidClassAttribute</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Should Jasper issue an error when
the value of the class attribute in an useBean action is not a valid
bean class</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">fork</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Only relevant if you use Ant to compile jsps: by default Jetty will use the Eclipse jdt compiler.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">genStrAsCharArray</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Option for generating Strings as char arrays.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">ieClassId</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The class-id value to be sent to Internet Explorer when
using &lt;jsp:plugin&gt; tags.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">clsid:8AD9C840-044E-11D1-B3E9-00805F499D93</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">javaEncoding</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Pass through the encoding to use for the compilation.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">UTF8</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jspIdleTimeout</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The amount of time in seconds a JSP can be idle before
it is unloaded. A value of zero or less indicates never unload.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">keepgenerated</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Do you want to keep the generated Java files around?</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">mappedFile</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Support for mapped Files. Generates a servlet that has a
print statement per line of the JSP file </p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">maxLoadedJsps</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The maximum number of JSPs that will be loaded for a web
application. If more than this number of JSPs are loaded, the least
recently used JSPs will be unloaded so that the number of JSPs loaded at
any one time does not exceed this limit. A value of zero or less
indicates no limit.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">modificationTestInterval</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If <code>development=true</code>, interval between
recompilation checks, triggered by a request.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">quoteAttributeEL</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">When EL is used in an attribute value on a JSP page, should the rules for quoting of attributes described in JSP.1.6 be applied to the expression</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">recompileOnFail</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If a JSP compilation fails should the
modificationTestInterval be ignored and the next access trigger a
re-compilation attempt? Used in development mode only and is disabled by
default as compilation may be expensive and could lead to excessive
resource usage.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">scratchDir</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Directory where servlets are generated. The default is the value of the context attribute <code>javax.servlet.context.tempdir</code>, or the system property <code>java.io.tmpdir</code> if the context attribute is not set.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">strictQuoteEscaping</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Should the quote escaping required by section JSP.1.6 of the JSP specification be applied to scriplet expression.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">suppressSmap</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Generation of SMAP info for JSR45 debugging.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">trimSpaces</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Should template text that consists entirely of whitespace be removed from the output (true), replaced with a single space (single) or left unchanged (false)? Note that if a JSP page or tag file specifies a trimDirectiveWhitespaces value of true, that will take precedence over this configuration setting for that page/tag.
trimmed?</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">–</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">xpoweredBy</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Generate an X-Powered-By response header.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect4">
<h5 id="configuring-jsp-for-jetty"><a class="anchor" href="#configuring-jsp-for-jetty"></a><a class="link" href="#configuring-jsp-for-jetty">Configuration</a></h5>
<div class="paragraph">
<p>The JSP engine has many configuration parameters.
Some parameters affect only precompilation, and some affect runtime recompilation checking.
Parameters also differ among the various versions of the JSP engine.
This page lists the configuration parameters, their meanings, and their default settings.
Set all parameters on the <code>org.eclipse.jetty.jsp.JettyJspServlet</code> instance defined in the <a href="#webdefault-xml"><code>webdefault.xml</code></a> file.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Be careful: for all of these parameters, if the value you set doesn&#8217;t take effect, try using all lower case instead of camel case, or capitalizing only some of the words in the name, as JSP is inconsistent in its parameter naming strategy.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
</div>
<div class="sect3">
<h4 id="modifying-configuration"><a class="anchor" href="#modifying-configuration"></a><a class="link" href="#modifying-configuration">Modifying Configuration</a></h4>
<div class="sect4">
<h5 id="overriding-webdefault.xml"><a class="anchor" href="#overriding-webdefault.xml"></a><a class="link" href="#overriding-webdefault.xml">Overriding <code>webdefault.xml</code></a></h5>
<div class="paragraph">
<p>You can make a copy of the <a href="#webdefault-xml">{$jetty.home}/etc/webdefault.xml</a> that ships with Jetty, apply your changes, and use it instead of the shipped version.
The example below shows how to do this when using the Jetty Maven plugin.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;plugin&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-maven-plugin<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;configuration&gt;</span>
<span class="tag">&lt;webApp&gt;</span>
<span class="tag">&lt;defaultsDescriptor&gt;</span>src/main/resources/webdefault.xml<span class="tag">&lt;/defaultsDescriptor&gt;</span>
<span class="tag">&lt;/webApp&gt;</span>
<span class="tag">&lt;/plugin&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>If you are using the Jetty distribution, and you want to change the JSP settings for just one or a few of your webapps, copy the <code>{$jetty.home}/etc/webdefault.xml</code> file somewhere, modify it, and then use a <a href="#intro-jetty-configuration-contexts">context xml</a> file to set this file as the <code>defaultsDescriptor</code> for your webapp. Here&#8217;s a snippet:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/foo<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Property</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/webapps/foobar.war<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">defaultsDescriptor</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/home/smith/dev/webdefault.xml<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>If you want to change the JSP settings for all webapps, edit the <code>{$jetty.home}/etc/webdefaults.xml</code> file directly instead.</p>
</div>
</div>
<div class="sect4">
<h5 id="configuring-jsp-servlet-in-web.xml"><a class="anchor" href="#configuring-jsp-servlet-in-web.xml"></a><a class="link" href="#configuring-jsp-servlet-in-web.xml">Configuring the JSP Servlet in web.xml</a></h5>
<div class="paragraph">
<p>Another option is to add an entry for the JSPServlet to the <code>WEB-INF/web.xml</code> file of your webapp and change or add init-params.
You may also add (but not remove) servlet-mappings.
You can use the entry in <a href="#webdefault-xml">{$jetty.home}/etc/webdefault.xml</a> as a starting point.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;servlet</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jsp</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;servlet-name&gt;</span>jsp<span class="tag">&lt;/servlet-name&gt;</span>
<span class="tag">&lt;servlet-class&gt;</span>org.eclipse.jetty.jsp.JettyJspServlet<span class="tag">&lt;/servlet-class&gt;</span>
<span class="tag">&lt;init-param&gt;</span>
<span class="tag">&lt;param-name&gt;</span>keepgenerated<span class="tag">&lt;/param-name&gt;</span>
<span class="tag">&lt;param-value&gt;</span>true<span class="tag">&lt;/param-value&gt;</span>
<span class="tag">&lt;/init-param&gt;</span>
...
<span class="tag">&lt;load-on-startup&gt;</span>0<span class="tag">&lt;/load-on-startup&gt;</span>
<span class="tag">&lt;/servlet&gt;</span>
<span class="tag">&lt;servlet-mapping&gt;</span>
<span class="tag">&lt;servlet-name&gt;</span>jsp<span class="tag">&lt;/servlet-name&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>*.jsp<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>*.jspf<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>*.jspx<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>*.xsp<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>*.JSP<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>*.JSPF<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>*.JSPX<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>*.XSP<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;/servlet-mapping&gt;</span>
<span class="tag">&lt;servlet</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">my-servlet</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;servlet-name&gt;</span>myServlet<span class="tag">&lt;/servlet-name&gt;</span>
<span class="tag">&lt;servlet-class&gt;</span>com.acme.servlet.MyServlet<span class="tag">&lt;/servlet-class&gt;</span>
...</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="jsp-async-support"><a class="anchor" href="#jsp-async-support"></a><a class="link" href="#jsp-async-support">Configuring Async Support</a></h5>
<div class="paragraph">
<p>By default, Jetty does not enable async support for the JSP servlet.
Configuring the JSP servlet for async is relatively easy - simply define the <code>async-supported</code> parameter as <code>true</code> in either your <code>webdefault.xml</code> or the <code>web.xml</code> for a specific context.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;servlet</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jsp</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;servlet-name&gt;</span>jsp<span class="tag">&lt;/servlet-name&gt;</span>
<span class="tag">&lt;async-supported&gt;</span>true<span class="tag">&lt;/async-supported&gt;</span>
<span class="tag">&lt;/servlet&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="using-jstl-taglibs-for-jetty7-jetty8"><a class="anchor" href="#using-jstl-taglibs-for-jetty7-jetty8"></a><a class="link" href="#using-jstl-taglibs-for-jetty7-jetty8">Using JSTL Taglibs</a></h4>
<div class="paragraph">
<p>The JavaServer Pages Standlard Tag Library (JSTL) is part of the Jetty distribution and is automatically put on the classpath when you <a href="#which-jsp-implementation">select your flavour of JSP</a>.
It is also automatically on the classpath for the Jetty Maven plugin, which uses the Apache JSP engine.</p>
</div>
<div class="sect4">
<h5 id="_embedding-2"><a class="anchor" href="#_embedding-2"></a><a class="link" href="#_embedding-2">Embedding</a></h5>
<div class="paragraph">
<p>If you are using Jetty in an embedded scenario, and you need to use JSTL, then you must ensure that the JSTL jars are included on the <em>container&#8217;s</em> classpath - that is the classpath that is the <em>parent</em> of the webapp&#8217;s classpath.
This is a restriction that arises from the JavaEE specification.</p>
</div>
<div class="sect5">
<h6 id="_apache-jsp"><a class="anchor" href="#_apache-jsp"></a><a class="link" href="#_apache-jsp">Apache JSP</a></h6>
<div class="paragraph">
<p>You will need to put the jars that are present in the <code>{$jetty.home}/lib/apache-jstl</code> directory onto the <em>container&#8217;s</em> classpath.
The Apache JSP engine will find the JSTL tag definitions inside these jars during startup.</p>
</div>
<div class="paragraph">
<p>As an efficiency enhancement, you can have jetty examine the JSTL jars to find the tags, and pre-feed them into the Apache JSP engine.
This is more efficient, because jetty will only scan the jars you tell it to, whereas the Apache JSP engine will scan every jar, which can be time-consuming in applications with a lot of jars on the container classpath.</p>
</div>
<div class="paragraph">
<p>To take advantage of this efficiency enhancement, set up the <a href="#container-include-jar-pattern">org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</a> to include a <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">pattern</a> that will match the names of the JSTL jars.
The <a href="#embedded-examples">Embedded Examples</a> section includes a <a href="#embedded-webapp-jsp">worked code example</a> of how to do this.
Below is a snippet from the example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"> webapp.setAttribute(<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">.*/[^/]*taglibs.*</span><span class="char">\\</span><span class="content">.jar$</span><span class="delimiter">&quot;</span></span>);</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="using-jsf-taglibs"><a class="anchor" href="#using-jsf-taglibs"></a><a class="link" href="#using-jsf-taglibs">Using JSF Taglibs</a></h4>
<div class="paragraph">
<p>The following sections provide information about using JSF TagLibs with Jetty Standalone and the Jetty Maven Plugin.</p>
</div>
<div class="sect4">
<h5 id="using-jsf-taglibs-with-jetty-standalone"><a class="anchor" href="#using-jsf-taglibs-with-jetty-standalone"></a><a class="link" href="#using-jsf-taglibs-with-jetty-standalone">Using JSF Taglibs with Jetty Distribution</a></h5>
<div class="paragraph">
<p>If you want to use JSF with your webapp, you need to copy the JSF implementation Jar (whichever Jar contains the <code>META-INF/*.tld</code> files from your chosen JSF implementation) into Jetty&#8217;s shared container lib directory.
You can either put them into the lib directory for Apache <code>{$jetty.home}/lib/apache-jsp</code> or put them into <code>{$jetty.home}/lib/ext</code>.</p>
</div>
</div>
<div class="sect4">
<h5 id="using-jsf-taglibs-with-jetty-maven-plugin"><a class="anchor" href="#using-jsf-taglibs-with-jetty-maven-plugin"></a><a class="link" href="#using-jsf-taglibs-with-jetty-maven-plugin">Using JSF Taglibs with Jetty Maven Plugin</a></h5>
<div class="paragraph">
<p>You should make your JSF jars dependencies of the plugin and <em>not</em> the webapp itself.
For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;plugin&gt;</span>
<span class="tag">&lt;groupId&gt;</span>org.eclipse.jetty<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jetty-maven-plugin<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;configuration&gt;</span>
<span class="tag">&lt;webApp&gt;</span>
<span class="tag">&lt;contextPath&gt;</span>/${artifactId}<span class="tag">&lt;/contextPath&gt;</span>
<span class="tag">&lt;/webApp&gt;</span>
<span class="tag">&lt;/configuration&gt;</span>
<span class="tag">&lt;dependencies&gt;</span>
<span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>com.sun.faces<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jsf-api<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>2.0.8<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span>
<span class="tag">&lt;dependency&gt;</span>
<span class="tag">&lt;groupId&gt;</span>com.sun.faces<span class="tag">&lt;/groupId&gt;</span>
<span class="tag">&lt;artifactId&gt;</span>jsf-impl<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;version&gt;</span>2.0.8<span class="tag">&lt;/version&gt;</span>
<span class="tag">&lt;/dependency&gt;</span>
<span class="tag">&lt;/dependencies&gt;</span>
<span class="tag">&lt;/plugin&gt;</span></code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="configuring-logging"><a class="anchor" href="#configuring-logging"></a><a class="link" href="#configuring-logging">Jetty Logging</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>This chapter discusses various options for configuring logging.</p>
</div>
<div class="sect2">
<h3 id="configuring-jetty-logging"><a class="anchor" href="#configuring-jetty-logging"></a><a class="link" href="#configuring-jetty-logging">Configuring Jetty Logging</a></h3>
<div class="paragraph">
<p>Jetty provides logging via its own <code>org.eclipse.jetty.util.log.Logger</code> layer, and does not natively use any existing Java logging framework.
All logging events, produced via the Jetty logging layer, have a name, a level, and a message.
The name is a FQCN (fully qualified class name) similar to how all existing Java logging frameworks operate.</p>
</div>
<div class="paragraph">
<p>Jetty logging, however, has a slightly different set of levels that it uses internally:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">WARN</dt>
<dd>
<p>For events serious enough to inform and log, but not fatal.</p>
</dd>
<dt class="hdlist1">INFO</dt>
<dd>
<p>Informational events.</p>
</dd>
<dt class="hdlist1">DEBUG</dt>
<dd>
<p>Debugging events (very noisy).</p>
</dd>
<dt class="hdlist1">IGNORE</dt>
<dd>
<p>Exception events that you can safely ignore, but useful for some people.
You might see this level as DEBUG under some Java logging framework configurations, where it retains the <em>ignore</em> phrase somewhere in the logging.</p>
</dd>
</dl>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Jetty logging produces no FATAL or SEVERE events.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect3">
<h4 id="selecting-log-framework"><a class="anchor" href="#selecting-log-framework"></a><a class="link" href="#selecting-log-framework">Selecting the Log Framework</a></h4>
<div class="paragraph">
<p>Configure the Jetty logging layer via the <code>org.eclipse.jetty.util.log.Log</code> class, following <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java">these rules</a>.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Load Properties</p>
<div class="ulist">
<ul>
<li>
<p>First from a Classpath Resource called <code>jetty-logging.properties</code> (if found).</p>
</li>
<li>
<p>Then from the <code>System.getProperties()</code>.</p>
</li>
</ul>
</div>
</li>
<li>
<p>Determine the log implementation.</p>
<div class="ulist">
<ul>
<li>
<p>If property <code>org.eclipse.jetty.util.log.class</code> is defined, load the class it defines as the logger implementation from the server <code>classpath</code>.</p>
</li>
<li>
<p>If the class <code>org.slf4j.Logger</code> exists in server classpath, the Jetty implementation becomes <code>org.eclipse.jetty.util.log.Slf4jLog</code>.</p>
</li>
<li>
<p>If no logger implementation is specified, default to <code>org.eclipse.jetty.util.log.StdErrLog</code>.</p>
</li>
</ul>
</div>
</li>
</ol>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
You can create your own custom logging by providing an implementation of the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10org/eclipse/jetty/util/log/Logger.html">Jetty Logger API</a>.
For an example of a custom logger, see <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java">JavaUtilLog.java</a>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="configuring-jetty-stderrlog"><a class="anchor" href="#configuring-jetty-stderrlog"></a><a class="link" href="#configuring-jetty-stderrlog">The jetty-logging.properties file</a></h4>
<div class="paragraph">
<p>By default, the internal Jetty Logging discovery mechanism will load logging specific properties from a classpath resource called <code>jetty-logging.properties</code> and then initialize the Logging from a combination of properties found in that file, along with any System Properties.
A typical jetty-logging.properties file will include at least the declaration of which logging implementation you want to use by defining a value for the <code>org.eclipse.jetty.util.log.class</code> property.</p>
</div>
<div class="paragraph">
<p>Examples for various logging frameworks can be found later in this documentation.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Default Logging with <a href="#default-logging-with-stderrlog">Jetty&#8217;s StdErrLog</a></p>
</li>
<li>
<p>Using <a href="#example-logging-log4j">Log4j or Log4j2 via SLF4J</a></p>
</li>
<li>
<p>Using <a href="#example-logging-logback">Logback via SLF4J</a></p>
</li>
<li>
<p>Using <a href="#example-logging-java-util-logging">Java Util Logging via SLF4J</a></p>
</li>
<li>
<p>Using <a href="#example-logging-java-commons-logging">Java Commons Logging via SLF4J</a></p>
</li>
<li>
<p><a href="#example-logging-logback-centralized">Centralized Logging with Logback and Sfl4jLog</a></p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect2">
<h3 id="default-logging-with-stderrlog"><a class="anchor" href="#default-logging-with-stderrlog"></a><a class="link" href="#default-logging-with-stderrlog">Default Logging with Jetty&#8217;s StdErrLog</a></h3>
<div class="sect3">
<h4 id="stderrlog-configuration"><a class="anchor" href="#stderrlog-configuration"></a><a class="link" href="#stderrlog-configuration">StdErrLog Configuration</a></h4>
<div class="paragraph">
<p>If you do nothing to configure a separate logging framework, Jetty will default to using an internal <code>org.eclipse.jetty.util.log.StdErrLog</code> implementation.
This will output all logging events to STDERR (aka <code>System.err</code>).</p>
</div>
<div class="paragraph">
<p>Simply use Jetty and <code>StdErrLog</code>-based logging is output to the console.</p>
</div>
<div class="paragraph">
<p>Included in the Jetty distribution is a logging module named <code>console-capture</code> that is capable of performing simple capturing of all STDOUT (<code>System.out</code>) and STDERR (<code>System.err</code>) output to a file that is rotated daily.</p>
</div>
<div class="paragraph">
<p>To enable this feature, simply activate the <code>console-capture</code> module on the command line:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=console-capture
INFO : console-capture initialized in ${jetty.base}/start.d/console-capture.ini
MKDIR : ${jetty.base}/logs
INFO : Base directory was modified
[my-base]$ tree
.
├── logs
└── start.d
└── console-capture.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>The default configuration for logging output will create a file <code>${jetty.base}/logs/yyyy_mm_dd.stderrout.log</code> which allows configuration of the output directory by setting the <code>jetty.logs</code> property.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
By default, logs are not set to be appended, meaning a the log file is wiped clean upon sever restart.
You can change this setting by editing the <code>console-capture.ini</code> and un-commenting the line that reads <code>jetty.console-capture.append=true</code>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>Just enabling the <code>console-capture</code> will simply output the values of STDERR and STDOUT to a log file.
To customize the log further, a module named <code>logging-jetty</code> is available to provides a default properties file to configure.
As with <code>console-capture</code>, you activate the <code>logging-jetty</code> on the command line.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=logging-jetty
INFO : logging-jetty initialized in ${jetty.base}/start.d/logging-jetty.ini
INFO : resources transitively enabled
MKDIR : ${jetty.base}/resources
COPY : ${jetty.home}/modules/logging-jetty/resources/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties
INFO : Base directory was modified
[my-base]$ tree
.
├── logs
├── resources
│   └── jetty-logging.properties
└── start.d
├── console-capture.ini
└── logging-jetty.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>Once activated, you can find the properties file at <code>${jetty.base}/resources/jetty-logging.properties</code>.
By default, the following parameters are defined.
To change them, un-comment the line and substitute your naming scheme and configuration choices.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="properties">## Force jetty logging implementation
#org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
## Set logging levels from: ALL, DEBUG, INFO, WARN, OFF
#org.eclipse.jetty.LEVEL=INFO
#com.example.LEVEL=INFO
## Hide stacks traces in logs?
#com.example.STACKS=false
## Show the source file of a log location?
#com.example.SOURCE=false</code></pre>
</div>
</div>
<div class="paragraph">
<p>There are a number of properties that can be defined in the configuration that will affect the behavior of StdErr logging with <code>console-capture</code>.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>&lt;name&gt;.LEVEL=&lt;level&gt;</code></dt>
<dd>
<p>Sets the logging level for all loggers within the <code>name</code> specified to the level, which can be (in increasing order of restriction) <code>ALL</code>, <code>DEBUG</code>, <code>INFO</code>, <code>WARN</code>, <code>OFF</code>.
The name (or hierarchy) can be a specific fully qualified class or a package namespace.
For example, <code>org.eclipse.jetty.http.LEVEL=DEBUG</code> is a package namespace approach to turn all loggers in the Jetty HTTP package to DEBUG level, and <code>org.eclipse.jetty.io.ChanelEndPoint.LEVEL=ALL</code> turns on all logging events for the specific class, including <code>DEBUG</code>, <code>INFO</code>, <code>WARN</code> (and even special internally ignored exception classes).
If more than one system property specifies a logging level, the most specific one applies.</p>
</dd>
<dt class="hdlist1"><code>&lt;name&gt;.SOURCE=&lt;boolean&gt;</code></dt>
<dd>
<p>Named Logger specific, attempts to print the Java source file name and line number from where the logging event originated.
Name must be a fully qualified class name (this configurable does not support package name hierarchy).
Default is false.
Be aware that this is a slow operation and has an impact on performance.</p>
</dd>
<dt class="hdlist1"><code>&lt;name&gt;.STACKS=&lt;boolean&gt;</code></dt>
<dd>
<p>Named Logger specific, controls the display of stacktraces.
Name must be a fully qualified class name (this configurable does not support package name hierarchy).
Default is true.</p>
</dd>
<dt class="hdlist1"><code>org.eclipse.jetty.util.log.stderr.SOURCE=&lt;boolean&gt;</code></dt>
<dd>
<p>Special Global Configuration.
Attempts to print the Java source file name and line number from where the logging event originated.
Default is false.</p>
</dd>
<dt class="hdlist1"><code>org.eclipse.jetty.util.log.stderr.LONG=&lt;boolean&gt;</code></dt>
<dd>
<p>Special Global Configuration.
When true, outputs logging events to <code>STDERR</code> using long form, fully qualified class names.
When false, uses abbreviated package names.
Default is false.</p>
<div class="ulist">
<ul>
<li>
<p>Example when set to false:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">2016-10-21 15:31:01.248:INFO::main: Logging initialized @332ms to org.eclipse.jetty.util.log.StdErrLog
2016-10-21 15:31:01.370:INFO:oejs.Server:main: jetty-10.0.10
2016-10-21 15:31:01.400:INFO:oejs.AbstractConnector:main: Started ServerConnector@2c330fbc{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2016-10-21 15:31:01.400:INFO:oejs.Server:main: Started @485ms</code></pre>
</div>
</div>
</li>
<li>
<p>Example when set to true:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">2016-10-21 15:31:35.020:INFO::main: Logging initialized @340ms to org.eclipse.jetty.util.log.StdErrLog
2016-10-21 15:31:35.144:INFO:org.eclipse.jetty.server.Server:main: jetty-10.0.10
2016-10-21 15:31:35.174:INFO:org.eclipse.jetty.server.AbstractConnector:main: Started ServerConnector@edf4efb{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2016-10-21 15:31:35.175:INFO:org.eclipse.jetty.server.Server:main: Started @495ms</code></pre>
</div>
</div>
</li>
</ul>
</div>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="deprecated-parameters"><a class="anchor" href="#deprecated-parameters"></a><a class="link" href="#deprecated-parameters">Deprecated Parameters</a></h4>
<div class="paragraph">
<p>These parameters existed in prior versions of Jetty, and are no longer supported.
They are included here for historical (and search engine) reasons.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>org.eclipse.jetty.util.log.DEBUG</code></dt>
<dd>
<p>Formerly used to enable DEBUG level logging on any logger used within Jetty (not just Jetty&#8217;s own logger).</p>
<div class="ulist">
<ul>
<li>
<p>Replaced with using the logger implementation specific configuration and level filtering.</p>
</li>
</ul>
</div>
</dd>
<dt class="hdlist1"><code>org.eclipse.jetty.util.log.stderr.DEBUG</code></dt>
<dd>
<p>Formerly used to enable DEBUG level logging on the internal Jetty <code>StdErrLog</code> implementation.</p>
<div class="ulist">
<ul>
<li>
<p>Replaced with level specific equivalent.
Example: <code>org.eclipse.jetty.LEVEL=DEBUG</code></p>
</li>
</ul>
</div>
</dd>
<dt class="hdlist1"><code>DEBUG</code></dt>
<dd>
<p>Ancient debugging flag that turned on all debugging, even non-logging debugging.</p>
<div class="ulist">
<ul>
<li>
<p>Jetty no longer uses because many third party libraries employ this overly simple property name, which would generate far too much console output.</p>
</li>
</ul>
</div>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect2">
<h3 id="configuring-logging-modules"><a class="anchor" href="#configuring-logging-modules"></a><a class="link" href="#configuring-logging-modules">Jetty Logging Integrations (SLF4J, Log4j, Logback, JCL, JUL)</a></h3>
<div class="paragraph">
<p>Jetty provides support for several logging frameworks including SLF4J, Java Commons Logging (JCL), Java Util Logging (JUL), Log4j (including version 2), and Logback.
This page includes examples of how to enable the associated modules for these different frameworks.
These modules are designed to capture container/server logs; <a href="#configuring-jetty-request-logs">request logs</a> and application logs need to be configured separately.
Please note that enabling these modules provides typical and basic functionality for each framework; advanced implementations may require their <a href="#startup-modules">own modules</a> or additional configuration.</p>
</div>
<div class="paragraph">
<p>Enabling these frameworks in the Jetty distribution is as easy as activating any other module, by adding <code>--add-to-start=&lt;module name&gt;</code> to the start command for your server, such as:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=logging-jetty
INFO : logging-jetty initialized in ${jetty.base}/start.d/logging-jetty.ini
INFO : resources transitively enabled
MKDIR : ${jetty.base}/resources
COPY : ${jetty.home}/modules/logging-jetty/resources/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties
INFO : Base directory was modified</code></pre>
</div>
</div>
<div class="paragraph">
<p>As noted above, Jetty supports a wide array of logging technologies.
If a particular logging framework requires additional jar files, Jetty will automatically download these as part of enabling the associated module and any dependent modules will be transitively enabled.</p>
</div>
<div class="paragraph">
<p>A list of the base Jetty logging modules by running <code>java -jar &lt;path-to-jetty.home&gt;/start.jar --list-modules=logging,-internal</code>.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">logging-jcl</dt>
<dd>
<p>Configures Jetty logging to use Java Commons Logging (JCL), using SLF4J as a binding.</p>
</dd>
<dt class="hdlist1">logging-jetty</dt>
<dd>
<p>Standard Jetty logging that captures <code>System.err</code> and <code>System.out</code> output.</p>
</dd>
<dt class="hdlist1">logging-jul</dt>
<dd>
<p>Configures Jetty logging to use Java Util Logging (JUL), using SLF4J as a binding.</p>
</dd>
<dt class="hdlist1">logging-log4j</dt>
<dd>
<p>Configures Jetty logging to use Log4j as the logging implementation, using SLF4J as a binding.</p>
</dd>
<dt class="hdlist1">logging-log4j2</dt>
<dd>
<p>Configures Jetty logging to use Log4j2 as the logging implementation, using SLF4J as a binding.</p>
</dd>
<dt class="hdlist1">logging-logback</dt>
<dd>
<p>Configures Jetty logging to use Logback as the logging implementation, using SLF4J as a binding.</p>
</dd>
<dt class="hdlist1">logging-slf4j</dt>
<dd>
<p>Configures Jetty logging to use SLF4J and provides a <code>slf4j-impl</code> which can be used by other logging frameworks.
If no other logging is configured, <code>slf4j-simple</code> is used.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>You can view a list of <strong>all</strong> the Jetty logging modules by running <code>java -jar &lt;path-to-jetty.home&gt;/start.jar --list-modules=logging</code>.
This will display all logging modules, including implementation and binding modules.</p>
</div>
<div class="paragraph">
<p>All these modules (with the exception of <code>logging-jetty</code>) arrange for the Jetty private logging API to be routed to the named technology to actually be logged.
For example, enabling the <code>logging-log4j</code> module will do several things:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>it enables an internal Log4j API module so that any container code that uses Log4j will find the API.</p>
</li>
<li>
<p>it enables an internal Log4j Implementation so that any container code that uses the Log4j API will also use a Log4j implementation to handle the logs (and all the normal Log4j configuration mechanisms etc.)</p>
</li>
<li>
<p>it enables the internal <code>slf4j-log4j</code> logging binding so that any container code that uses the SLF4j API to also use the Log4j implementation via the Log4j API.</p>
</li>
<li>
<p>it configures the Jetty logging API to use the SLF4J API, which is then bound to Log4j.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>So, after enabling <code>logging-log4j</code>, within the server container there are 3 logging APIs available: Jetty, SLF4J and Log4J.
But there is only a single logging <strong>implementation</strong> - Log4j; the 3 APIs act only as facades over the Log4j implementation.</p>
</div>
<div class="paragraph">
<p>Note that you can add additional APIs to this configuration.
For example, enabling the internal module <code>jcl-slf4j</code> would add in a Java Commons Logging facade that also would use the Log4j implementation via the SLF4J binding.</p>
</div>
<div class="paragraph">
<p>Most other top level logging modules work in the same way: <code>logging-jcl</code>, <code>logging-jul</code>, <code>logging-slf4j</code>, <code>logging-log4j2</code> and <code>logging-logback</code> all bind their implementation via SLF4J.</p>
</div>
<div class="sect3">
<h4 id="example-logging-slf4j"><a class="anchor" href="#example-logging-slf4j"></a><a class="link" href="#example-logging-slf4j">Logging with SLF4J</a></h4>
<div class="paragraph">
<p>Jetty uses the SLF4J api as a binding to provide logging information to additional frameworks such as Log4j or Logback.
It can also be used on it&#8217;s own to provide simple server logging.
To enable the SLF4J framework, you need to activate the <code>logging-slf4j</code> module.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=logging-slf4j
ALERT: There are enabled module(s) with licenses.
The following 1 module(s):
+ contains software not provided by the Eclipse Foundation!
+ contains software not covered by the Eclipse Public License!
+ has not been audited for compliance with its license
Module: slf4j-api
+ SLF4J is distributed under the MIT License.
+ Copyright (c) 2004-2013 QOS.ch
+ All rights reserved.
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ &quot;Software&quot;), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Proceed (y/N)? y
INFO : slf4j-api transitively enabled
INFO : logging-slf4j initialized in ${jetty.base}/start.d/logging-slf4j.ini
MKDIR : ${jetty.base}/lib/slf4j
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar
INFO : Base directory was modified
ERROR : Module logging-slf4j requires a module providing slf4j-impl from one of [slf4j-simple-impl, slf4j-logback, slf4j-jul, slf4j-log4j2, slf4j-log4j]
ERROR : Unsatisfied module dependencies: logging-slf4j
Usage: java -jar $JETTY_HOME/start.jar [options] [properties] [configs]
java -jar $JETTY_HOME/start.jar --help # for more information</code></pre>
</div>
</div>
<div class="paragraph">
<p>As you probably noticed, the system gives an <code>ERROR</code> when trying to enable the <code>logging-slf4j</code> on it&#8217;s own.
The <code>logging-slf4j</code> module itself provides the SLF4J api, but as SLF4J is often used as a binding for other logging frameworks does not by default provide an implementation.
To enable the simple SLF4J implementation, we will also need to activate the <code>slf4j-simple-impl</code> module.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=slf4j-simple-impl
INFO : slf4j-simple-impl initialized in ${jetty.base}/start.d/slf4j-simple-impl.ini
INFO : resources transitively enabled
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-simple-1.7.21.jar
MKDIR : ${jetty.base}/resources
COPY : ${jetty.home}/modules/slf4j-simple-impl/resources/simplelogger.properties to ${jetty.base}/resources/simplelogger.properties
INFO : Base directory was modified
[my-base]$ tree
.
├── lib
│   └── slf4j
│   ├── slf4j-api-1.7.21.jar
│   └── slf4j-simple-1.7.21.jar
├── resources
│   └── simplelogger.properties
└── start.d
├── logging-slf4j.ini
└── slf4j-simple-impl.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>Jetty is now configured to log using the SLF4J framework.
A standard SLF4J properties file is located in <code>${jetty.base}/resources/simplelogger.properties</code>.</p>
</div>
</div>
<div class="sect3">
<h4 id="example-logging-log4j"><a class="anchor" href="#example-logging-log4j"></a><a class="link" href="#example-logging-log4j">Logging with Log4j and Log4j2</a></h4>
<div class="paragraph">
<p>It is possible to have the Jetty Server logging configured so that Log4j or Log4j2 controls the output of logging events produced by Jetty.
This is accomplished by configuring Jetty for logging to <a href="http://logging.apache.org/log4j/">Apache Log4j</a> via <a href="http://slf4j.org/manual.html">Slf4j</a> and the <a href="http://slf4j.org/manual.html#swapping">Slf4j binding layer for Log4j</a>.
Implementation of Log4j can be done by enabling the <code>logging-log4j</code> module.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=logging-log4j
ALERT: There are enabled module(s) with licenses.
The following 2 module(s):
+ contains software not provided by the Eclipse Foundation!
+ contains software not covered by the Eclipse Public License!
+ has not been audited for compliance with its license
Module: log4j-impl
+ Log4j is released under the Apache 2.0 license.
+ http://www.apache.org/licenses/LICENSE-2.0.html
Module: slf4j-api
+ SLF4J is distributed under the MIT License.
+ Copyright (c) 2004-2013 QOS.ch
+ All rights reserved.
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ &quot;Software&quot;), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Proceed (y/N)? y
INFO : slf4j-api transitively enabled
INFO : log4j-impl transitively enabled
INFO : resources transitively enabled
INFO : slf4j-log4j transitively enabled
INFO : logging-log4j initialized in ${jetty.base}/start.d/logging-log4j.ini
MKDIR : ${jetty.base}/lib/slf4j
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar
MKDIR : ${jetty.base}/lib/log4j
COPY : /Users/admin/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar to ${jetty.base}/lib/log4j/log4j-1.2.17.jar
MKDIR : ${jetty.base}/resources
COPY : ${jetty.home}/modules/log4j-impl/resources/log4j.xml to ${jetty.base}/resources/log4j.xml
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-log4j12-1.7.21.jar
INFO : Base directory was modified
[my-base]$ tree
.
├── lib
│   ├── log4j
│   │   └── log4j-1.2.17.jar
│   └── slf4j
│   ├── slf4j-api-1.7.21.jar
│   └── slf4j-log4j12-1.7.21.jar
├── resources
│   └── log4j.xml
└── start.d
└── logging-log4j.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>Jetty is now configured to log using the Log4j framework.
A standard Log4j configuration file is located in <code>${jetty.base}/resources/log4j.xml</code>.</p>
</div>
<div class="paragraph">
<p>Or, to set up Log4j2, enable the <code>logging-log4j2</code> module.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=logging-log4j2
ALERT: There are enabled module(s) with licenses.
The following 2 module(s):
+ contains software not provided by the Eclipse Foundation!
+ contains software not covered by the Eclipse Public License!
+ has not been audited for compliance with its license
Module: log4j2-api
+ Log4j is released under the Apache 2.0 license.
+ http://www.apache.org/licenses/LICENSE-2.0.html
Module: slf4j-api
+ SLF4J is distributed under the MIT License.
+ Copyright (c) 2004-2013 QOS.ch
+ All rights reserved.
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ &quot;Software&quot;), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Proceed (y/N)? y
INFO : slf4j-api transitively enabled
INFO : logging-log4j2 initialized in ${jetty.base}/start.d/logging-log4j2.ini
INFO : log4j2-api transitively enabled
INFO : resources transitively enabled
INFO : slf4j-log4j2 transitively enabled
INFO : log4j2-impl transitively enabled
MKDIR : ${jetty.base}/lib/slf4j
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar
MKDIR : ${jetty.base}/lib/log4j2
DOWNLD: https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api/2.6.1/log4j-api-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-api-2.6.1.jar
MKDIR : ${jetty.base}/resources
DOWNLD: https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl/2.6.1/log4j-slf4j-impl-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-slf4j-impl-2.6.1.jar
DOWNLD: https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core/2.6.1/log4j-core-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-core-2.6.1.jar
COPY : ${jetty.home}/modules/log4j2-impl/resources/log4j2.xml to ${jetty.base}/resources/log4j2.xml
INFO : Base directory was modified
[my-base]$ tree
.
├── lib
│   ├── log4j2
│   │   ├── log4j-api-2.6.1.jar
│   │   ├── log4j-core-2.6.1.jar
│   │   └── log4j-slf4j-impl-2.6.1.jar
│   └── slf4j
│   └── slf4j-api-1.7.21.jar
├── resources
│   └── log4j2.xml
└── start.d
└── logging-log4j2.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>At this point Jetty is configured so that the Jetty server itself will log using Log4j2, using the Log4j2 configuration found in <code>{$jetty.base}/resources/log4j2.xml</code>.</p>
</div>
</div>
<div class="sect3">
<h4 id="example-logging-logback"><a class="anchor" href="#example-logging-logback"></a><a class="link" href="#example-logging-logback">Logging with Logback</a></h4>
<div class="paragraph">
<p>It is possible to have the Jetty Server logging configured so that Logback controls the output of logging events produced by Jetty.
This is accomplished by configuring Jetty for logging to <code>Logback</code>, which uses <a href="http://slf4j.org/manual.html">Slf4j</a> and the <a href="http://logback.qos.ch/">Logback Implementation for Slf4j</a>.</p>
</div>
<div class="paragraph">
<p>To set up Jetty logging via Logback, enable the <code>logging-logback</code> module.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=logging-logback
ALERT: There are enabled module(s) with licenses.
The following 2 module(s):
+ contains software not provided by the Eclipse Foundation!
+ contains software not covered by the Eclipse Public License!
+ has not been audited for compliance with its license
Module: logback-impl
+ Logback: the reliable, generic, fast and flexible logging framework.
+ Copyright (C) 1999-2012, QOS.ch. All rights reserved.
+ This program and the accompanying materials are dual-licensed under
+ either:
+ the terms of the Eclipse Public License v1.0
+ as published by the Eclipse Foundation:
+ http://www.eclipse.org/legal/epl-v10.html
+ or (per the licensee's choosing) under
+ the terms of the GNU Lesser General Public License version 2.1
+ as published by the Free Software Foundation:
+ http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
Module: slf4j-api
+ SLF4J is distributed under the MIT License.
+ Copyright (c) 2004-2013 QOS.ch
+ All rights reserved.
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ &quot;Software&quot;), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Proceed (y/N)? y
INFO : slf4j-api transitively enabled
INFO : logback-impl transitively enabled
INFO : slf4j-logback transitively enabled
INFO : logging-logback initialized in ${jetty.base}/start.d/logging-logback.ini
INFO : resources transitively enabled
MKDIR : ${jetty.base}/lib/slf4j
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar
MKDIR : ${jetty.base}/lib/logback
DOWNLD: https://repo1.maven.org/maven2/ch/qos/logback/logback-core/1.1.7/logback-core-1.1.7.jar to ${jetty.base}/lib/logback/logback-core-1.1.7.jar
MKDIR : ${jetty.base}/resources
COPY : ${jetty.home}/modules/logback-impl/resources/logback.xml to ${jetty.base}/resources/logback.xml
DOWNLD: https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar to ${jetty.base}/lib/logback/logback-classic-1.1.7.jar
INFO : Base directory was modified
[my-base]$ tree
.
├── lib
│   ├── logback
│   │   ├── logback-classic-1.1.7.jar
│   │   └── logback-core-1.1.7.jar
│   └── slf4j
│   └── slf4j-api-1.7.21.jar
├── resources
│   └── logback.xml
└── start.d
└── logging-logback.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>At this point Jetty is configured so that the Jetty server itself will log using Logback, using the Logback configuration found in <code>{$jetty.base}/resources/logback.xml</code>.</p>
</div>
</div>
<div class="sect3">
<h4 id="_logging-with-java-util-logging"><a class="anchor" href="#_logging-with-java-util-logging"></a><a class="link" href="#_logging-with-java-util-logging">Logging with Java Util Logging</a></h4>
<div class="sect4">
<h5 id="example-logging-java-util-logging"><a class="anchor" href="#example-logging-java-util-logging"></a><a class="link" href="#example-logging-java-util-logging">Java Util Logging with SLF4J</a></h5>
<div class="paragraph">
<p>It is possible to have the Jetty Server logging configured so that <code>java.util.logging</code> controls the output of logging events produced by Jetty.</p>
</div>
<div class="paragraph">
<p>This example demonstrates how to configuring Jetty for logging to <code>java.util.logging</code> via <a href="http://slf4j.org/manual.html">SLF4J</a> as a binding layer.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=logging-jul
ALERT: There are enabled module(s) with licenses.
The following 1 module(s):
+ contains software not provided by the Eclipse Foundation!
+ contains software not covered by the Eclipse Public License!
+ has not been audited for compliance with its license
Module: slf4j-api
+ SLF4J is distributed under the MIT License.
+ Copyright (c) 2004-2013 QOS.ch
+ All rights reserved.
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ &quot;Software&quot;), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Proceed (y/N)? y
INFO : jul-impl transitively enabled
INFO : slf4j-api transitively enabled
INFO : slf4j-jul transitively enabled
INFO : logging-jul initialized in ${jetty.base}/start.d/logging-jul.ini
INFO : resources transitively enabled
MKDIR : ${jetty.base}/etc
COPY : ${jetty.home}/modules/jul-impl/etc/java-util-logging.properties to ${jetty.base}/etc/java-util-logging.properties
MKDIR : ${jetty.base}/lib/slf4j
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/slf4j-jdk14/1.7.21/slf4j-jdk14-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-jdk14-1.7.21.jar
INFO : Base directory was modified
[my-base]$ tree
.
├── etc
│   └── java-util-logging.properties
├── lib
│   └── slf4j
│   ├── slf4j-api-1.7.21.jar
│   └── slf4j-jdk14-1.7.21.jar
└── start.d
└── logging-jul.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>Jetty is now configured to log using the JUL framework.
A standard JUL properties file is located in <code>${jetty.base}/etc/java-util-logging.properties</code>.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_capturing-console-output"><a class="anchor" href="#_capturing-console-output"></a><a class="link" href="#_capturing-console-output">Capturing Console Output</a></h4>
<div class="paragraph">
<p>By default, enabling the above modules will output log information to the console.
Included in the distribution is the <code>console-capture</code> module, which can be used in lieu of additional configuration to the selected logging module to capture this output to a <code>logs</code> directory in your <code>${jetty.base}</code>.
To enable this functionality, activate the <code>console-capture</code> module.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar --add-to-start=console-capture
INFO : console-capture initialized in ${jetty.base}/start.d/console-capture.ini
MKDIR : ${jetty.base}/logs
INFO : Base directory was modified
[my-base]$ tree
.
├── logs
└── start.d
└── console-capture.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>As an example, here is the output from Logback before using the <code>console-capture</code> module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar
419 [main] INFO org.eclipse.jetty.util.log - Logging initialized @508ms to org.eclipse.jetty.util.log.Slf4jLog
540 [main] INFO org.eclipse.jetty.server.Server - jetty-10.0.10
575 [main] INFO o.e.jetty.server.AbstractConnector - Started ServerConnector@3c0ecd4b{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
575 [main] INFO org.eclipse.jetty.server.Server - Started @668ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>After enabling <code>console-capture</code>, the output is as follows, which displays the location the log is being saved to:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[my-base]$ java -jar /path/to/jetty-home/start.jar
151 [main] INFO org.eclipse.jetty.util.log - Logging initialized @238ms to org.eclipse.jetty.util.log.Slf4jLog
196 [main] INFO org.eclipse.jetty.util.log - Console stderr/stdout captured to /installs/my-jetty-base/logs/2016_10_21.jetty.log</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="example-logging-logback-centralized"><a class="anchor" href="#example-logging-logback-centralized"></a><a class="link" href="#example-logging-logback-centralized">Centralized Logging using Logback</a></h3>
<div class="paragraph">
<p>The term <em>Centralized Logging</em> refers to a forced logging configuration for the Jetty Server and all web applications that are deployed on the server.
It routes all logging events from the web applications to a single configuration on the Server side.</p>
</div>
<div class="paragraph">
<p>The example below shows how to accomplish this with Jetty and Slf4j, using <code>Logback</code> to manage the final writing of logs to disk.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
This mechanism forces all webapps to use the server&#8217;s configuration for logging, something that isn&#8217;t 100% appropriate for all webapps.
An example would be having Jenkins-CI deployed as an webapp, if you force its logging configuration to the server side, you lose the ability on <a href="http://jenkins-ci.org/">Jenkins-CI</a> to see the logs from the various builds (as now those logs are actually going to the main server log).
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>This configuration is essentially the multiple logger configuration with added configuration to the deployers to force a <code>WebAppClassLoader</code> change to use the server classpath over the webapps classpath for the logger specific classes.</p>
</div>
<div class="paragraph">
<p>The technique used by this configuration is to provide an <a href="https://www.eclipse.org/jetty/javadoc/jetty-10org/eclipse/jetty/deploy/AppLifeCycle.Binding.html">AppLifeCycle.Binding</a> against the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/deploy/AppLifeCycle.html">`"deploying"`node</a> that modifies the
<a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#getSystemClasspathPattern()">WebAppContext.getSystemClasspathPattern().add(String)</a> for the common logging classes.
See <a href="https://github.com/jetty-project/jetty-webapp-logging/blob/master/jetty-webapp-logging/src/main/java/org/eclipse/jetty/webapp/logging/CentralizedWebAppLoggingBinding.java">org.eclipse.jetty.logging.CentralizedWebAppLoggingBinding</a> for actual implementation.</p>
</div>
<div class="paragraph">
<p>A convenient replacement <code>logging</code> module has been created to bootstrap your <code>${jetty.base}</code> directory for capturing all Jetty server logging from multiple logging frameworks into a single logging output file managed by Logback.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[mybase]$ curl -O https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-webapp-logging/9.4.27/jetty-webapp-logging-9.4.27-config.jar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3402 100 3402 0 0 15823 0 --:--:-- --:--:-- --:--:-- 15750
[mybase]$ jar -xf jetty-webapp-logging-9.4.27-config.jar
[my-base]$ java -jar /path/to/jetty-home/start.jar --create-startd --add-to-start=centralized-webapp-logging
ALERT: There are enabled module(s) with licenses.
The following 2 module(s):
+ contains software not provided by the Eclipse Foundation!
+ contains software not covered by the Eclipse Public License!
+ has not been audited for compliance with its license
Module: logback-impl
+ Logback: the reliable, generic, fast and flexible logging framework.
+ Copyright (C) 1999-2012, QOS.ch. All rights reserved.
+ This program and the accompanying materials are dual-licensed under
+ either:
+ the terms of the Eclipse Public License v1.0
+ as published by the Eclipse Foundation:
+ http://www.eclipse.org/legal/epl-v10.html
+ or (per the licensee's choosing) under
+ the terms of the GNU Lesser General Public License version 2.1
+ as published by the Free Software Foundation:
+ http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
Module: slf4j-api
+ SLF4J is distributed under the MIT License.
+ Copyright (c) 2004-2013 QOS.ch
+ All rights reserved.
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ &quot;Software&quot;), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Proceed (y/N)? y
INFO : slf4j-api transitively enabled
INFO : log4j-over-slf4j transitively enabled
INFO : jcl-slf4j transitively enabled
INFO : logback-impl transitively enabled
INFO : jul-slf4j transitively enabled
INFO : slf4j-logback transitively enabled
INFO : centralized-webapp-logging initialized in ${jetty.base}/start.d/centralized-webapp-logging.ini
INFO : logging-logback transitively enabled
INFO : resources transitively enabled
MKDIR : ${jetty.base}/lib/slf4j
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.25.jar
MKDIR : ${jetty.base}/lib/logging
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/log4j-over-slf4j/1.7.25/log4j-over-slf4j-1.7.25.jar to ${jetty.base}/lib/logging/log4j-over-slf4j-1.7.25.jar
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/jcl-over-slf4j/1.7.25/jcl-over-slf4j-1.7.25.jar to ${jetty.base}/lib/slf4j/jcl-over-slf4j-1.7.25.jar
MKDIR : ${jetty.base}/lib/logback
DOWNLD: https://repo1.maven.org/maven2/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar to ${jetty.base}/lib/logback/logback-core-1.2.3.jar
DOWNLD: https://repo1.maven.org/maven2/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar to ${jetty.base}/lib/slf4j/jul-to-slf4j-1.7.25.jar
COPY : ${jetty.home}/modules/jul-slf4j/etc/java-util-logging.properties to ${jetty.base}/etc/java-util-logging.properties
DOWNLD: https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar to ${jetty.base}/lib/logback/logback-classic-1.2.3.jar
MKDIR : ${jetty.base}/logs
DOWNLD: https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-webapp-logging/9.4.27/jetty-webapp-logging-9.4.27.jar to ${jetty.base}/lib/logging/jetty-webapp-logging-9.4.27.jar
INFO : Base directory was modified
$</code></pre>
</div>
</div>
<div class="paragraph">
<p>This replacement <code>centralized-webapp-logging.mod</code> performs a number of tasks.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><code>mybase</code> is a <code>${jetty.base}</code> directory.</p>
</li>
<li>
<p>The jetty-home is unpacked (and untouched) into <code>/opt/jetty-home/</code> and becomes the <code>${jetty.home}</code> directory for this demonstration.</p>
</li>
<li>
<p>The <code>curl</code> command downloads the replacement config overlay for the <code>${jetty.base}/modules/</code> directory to use.</p>
</li>
<li>
<p>The <code>start.jar --add-to-start=centralized-webapp-logging</code> command performs a number of steps to make the centralized-webapp-logging module available to the <code>${jetty.base}</code> configuration.</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>A new <code>${jetty.base}/start.d/centralized-webapp-logging.ini</code> configuration was created.</p>
</li>
<li>
<p>Required <code>${jetty.base}</code> directories are created: <code>${jetty.base}/logs</code> and <code>${jetty.base}/resources</code>.</p>
</li>
<li>
<p>Required logging libraries are downloaded (if not present already) to the <code>${jetty.base}/lib/logging/</code> directory:</p>
<div class="ulist">
<ul>
<li>
<p><code>slf4j-api.jar</code> - API jar for Slf4j (used by most of the rest of the jars)</p>
</li>
<li>
<p><code>log4j-over-slf4j.jar</code> - Slf4j jar that captures all log4j emitted logging events</p>
</li>
<li>
<p><code>jul-to-slf4j.jar</code> - Slf4j jar that captures all java.util.logging events</p>
</li>
<li>
<p><code>jcl-over-slf4j.jar</code> - Slf4j jar that captures all commons-logging events</p>
</li>
<li>
<p><code>logback-classic.jar</code> - the Slf4j adapter jar that routes all of the captured logging events to logback itself.</p>
</li>
<li>
<p><code>logback-core.jar</code> - the logback implementation jar, that handles all of the filtering and output of the logging events.</p>
</li>
</ul>
</div>
</li>
<li>
<p>Required webapp-logging library is downloaded (if not present already) to the <code>${jetty.base}/lib/webapp-logging/</code> directory:</p>
<div class="ulist">
<ul>
<li>
<p><code>jetty-webapp-logging.jar</code> - the Jetty side deployment manger app-lifecycle bindings for modifying the <code>WebAppClassloaders</code> of deployed webapps.</p>
</li>
</ul>
</div>
</li>
</ol>
</div>
</li>
</ol>
</div>
<div class="paragraph">
<p>At this point the Jetty <code>mybase</code> is configured so that the jetty server itself will log using slf4j, and all other logging events from other Jetty Server components (such as database drivers, security layers, jsp, mail, and other 3rd party server components) are routed to logback for filtering and output.</p>
</div>
<div class="paragraph">
<p>All webapps deployed via the <code>DeploymentManager</code> have their <code>WebAppClassLoader</code> modified to use server side classes and configuration for all logging implementations.</p>
</div>
<div class="paragraph">
<p>The server classpath can be verified by using the <code>start.jar --list-config</code> command.</p>
</div>
<div class="paragraph">
<p>In essence, Jetty is now configured to emit its own logging events to slf4j, and various slf4j bridge jars are acting on behalf of <code>log4j</code>, <code>java.util.logging</code>, and <code>commons-logging</code>, routing all of the logging events to <code>logback</code>
(a slf4j implementation) for routing (to console, file, etc&#8230;&#8203;).</p>
</div>
</div>
<div class="sect2">
<h3 id="jetty-maven-scanning"><a class="anchor" href="#jetty-maven-scanning"></a><a class="link" href="#jetty-maven-scanning">Files Scanned by the Jetty Maven Plugin</a></h3>
<div class="paragraph">
<p>If you set a non zero <code>scanIntervalSeconds</code> <a href="#jetty-maven-plugin">configuration parameter</a>, the <code>jetty-maven-plugin</code> will scan certain files for changes, and redeploy the webapp if necessary.
The files that are scanned depend on the goal being executed.</p>
</div>
<div class="sect3">
<h4 id="scanner-matrix"><a class="anchor" href="#scanner-matrix"></a><a class="link" href="#scanner-matrix">Scanner Matrix</a></h4>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 66.6667%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Goal</th>
<th class="tableblock halign-left valign-top">Files</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#jetty-run-goal">jetty:run</a></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="ulist">
<ul>
<li>
<p>pom.xml</p>
</li>
<li>
<p>&lt;dependencies&gt;</p>
</li>
<li>
<p>&lt;classesDirectory&gt;</p>
</li>
<li>
<p>&lt;testClassesDirectory&gt;</p>
</li>
<li>
<p>&lt;webApp&gt;&lt;descriptor/&gt;&lt;/webApp&gt; or src/main/webapp/WEB-INF/web.xml</p>
</li>
<li>
<p>&lt;webApp&gt;&lt;jettyEnvXml/&gt;&lt;/webApp&gt; or src/main/webapp/WEB-INF/jetty-web.xml</p>
</li>
<li>
<p>&lt;webApp&gt;&lt;baseResource&gt;/WEB-INF/jetty-web.xml</p>
</li>
<li>
<p>&lt;scanTargets&gt;</p>
</li>
<li>
<p>&lt;scanTargetPatterns&gt;</p>
</li>
<li>
<p>any <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setDefaultsDescriptor%28java.lang.String%29">defaultsDescriptor</a> for the webapp</p>
</li>
<li>
<p>any <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setOverrideDescriptor%28java.lang.String%29">overrideDescriptor</a> for the webapp</p>
</li>
<li>
<p>any dependencies that are wars or zips</p>
</li>
</ul>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#running-assembled-webapp-as-war">jetty:run-war</a></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="ulist">
<ul>
<li>
<p>pom.xml</p>
</li>
<li>
<p>&lt;war&gt;</p>
</li>
</ul>
</div></div></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="platforms"><a class="anchor" href="#platforms"></a><a class="link" href="#platforms">Platforms, Stacks and Alternative Distributions</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_many-many-options"><a class="anchor" href="#_many-many-options"></a><a class="link" href="#_many-many-options">Many many options&#8230;&#8203;</a></h3>
<div class="paragraph">
<p>In addition to using Jetty in its distribution form and its multiple embedded forms, there are a number of alternative ways to use Jetty.
Many products and open source projects out there distribute Jetty themselves, in both distribution and embedded forms, not to mention different operating systems bundling Jetty in other installable forms.</p>
</div>
<div class="paragraph">
<p>If your platform supports Jetty from a distribution or deployment perspective and want to be included on this list just fork the documentation and submit a pull request, or contact us.
Check out our list of <a href="http://www.eclipse.org/jetty/powered">Powered By</a> page for software that makes use of Jetty, often in novel and exciting ways.</p>
</div>
</div>
<div class="sect2">
<h3 id="jelastic"><a class="anchor" href="#jelastic"></a><a class="link" href="#jelastic">Jelastic</a></h3>
<div class="paragraph">
<p>Jelastic is a wonderful place to host your applications with solid support for Jetty.
As a cloud hosting platform they take the majority of configuration and installation details out of the picture and focus on letting you focus on your web application.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="http://jelastic.com/why">Why Jelastic?</a></p>
</li>
<li>
<p><a href="http://jelastic.com/jetty-hosting">Jetty Hosting</a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="cloudfoundry"><a class="anchor" href="#cloudfoundry"></a><a class="link" href="#cloudfoundry">CloudFoundry</a></h3>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
This is an increasingly aged integration, things like likely changed enough this is not directly useful but may serve as a useful starting point should someone want to look into it.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect3">
<h4 id="cloudfoundry-overview"><a class="anchor" href="#cloudfoundry-overview"></a><a class="link" href="#cloudfoundry-overview">Overview</a></h4>
<div class="paragraph">
<p><a href="http://www.cloudfoundry.com">CloudFoundry</a> is an open platform intended as a place to deploy end user applications in a manner which is both simple and eminently scalable to fit the needs of the application.
With the release of their V2 framework the Jetty project has created a buildpack which allows you to deploy your java based web application onto Jetty and still make use of the remainder of the CloudFoundry platform.</p>
</div>
<div class="paragraph">
<p>This buildpack itself is quite simple to use.
A collection of ruby scripting and the buildpack conventions will allow Jetty to be downloaded, configured and customized to your needs and then have your web application deployed onto it.
While the default buildpack we have created is useful to deploy a stock configuration of jetty, it is quite likely that you will want to fork the buildpack and tweak it to fit your immediate needs.
This process is made trivial since buildpacks install from a github repository.
For example, to change the jetty version simply fork it in GitHub and tweak the <code>JETTY_VERSION</code> string in the <code>jetty_web.rb</code> file.</p>
</div>
<div class="paragraph">
<p>If you have additional modifications to make to the Jetty server, like perhaps configuring additional static contexts, setting up a proxy servlet, adding jar files to the jetty home/lib/ext directory, etc you can either adapt the ruby scripting directly or place them under the appropriate location in the <code>/resources</code> directory of this buildpack and they will be copied into the correct location.</p>
</div>
<div class="paragraph">
<p>For the time being I&#8217;ll leave this buildpack under my personal github account and should there be interest expressed I am more then happy to push it over to <a href="https://github.com/jetty-project" class="bare">https://github.com/jetty-project</a> down the road for proper contributions, etc.</p>
</div>
</div>
<div class="sect3">
<h4 id="cloudfoundry-usage"><a class="anchor" href="#cloudfoundry-usage"></a><a class="link" href="#cloudfoundry-usage">Usage</a></h4>
<div class="paragraph">
<p>To show how incredibly easy it is to use the Jetty buildpack with cloudfoundry, this is all the more you need to do to deploy your application.
Refer to the CloudFoundry <a href="http://docs.cloudfoundry.com/">documentation</a> to get started, get the <code>cf</code> utilities installed and an environment configured.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ cf push snifftest --buildpack=git://github.com/jmcc0nn3ll/jetty-buildpack.git</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
In this example the web application is uploaded from the <strong>current</strong> directory so make sure you have changed directory into the root of your web application.
The <code>snifftest</code> on the commandline refers to what you are calling the application, not the directory to deploy.
Also note that the webapplication is installed into the <code>ROOT</code> context of Jetty as is available at the root context of the server.
Any additional web applications will have to be configured within the buildpack as mentioned above.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>You will be prompted to answer a series of questions describing the execution environment and any additional services you need enabled (databases, etc).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Instances&gt; 1
Custom startup command&gt; none
1: 64M
2: 128M
3: 256M
4: 512M
5: 1G
Memory Limit&gt; 256M
Creating snifftest... OK
1: snifftest
2: none
Subdomain&gt; snifftest
1: a1-app.cf-app.com
2: none
Domain&gt; a1-app.cf-app.com
Binding snifftest.a1-app.cf-app.com to snifftest... OK
Create services for application?&gt; n
Save configuration?&gt; n</code></pre>
</div>
</div>
<div class="paragraph">
<p>Once answered you will see the installation process of your application.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Uploading snifftest... OK
Starting snifftest... OK
-&gt; Downloaded app package (4.0K)
Initialized empty Git repository in /tmp/buildpacks/jetty-buildpack.git/.git/
Installing jetty-buildpack.git.
Downloading JDK...
Copying openjdk-1.7.0_21.tar.gz from the buildpack cache ...
Unpacking JDK to .jdk
Downloading Jetty: jetty-home-10.0.10.tar.gz
Downloading jetty-home-10.0.10.tar.gz from http://repo2.maven.org/maven2/org/eclipse/jetty/jetty-home/10.0.0.v202012xx/ ...
Unpacking Jetty to .jetty
-&gt; Uploading staged droplet (36M)
-&gt; Uploaded droplet
Checking snifftest...
Staging in progress...
Staging in progress...
Staging in progress...
Staging in progress...
Staging in progress...
Staging in progress...
0/1 instances: 1 starting
0/1 instances: 1 starting
0/1 instances: 1 starting
0/1 instances: 1 starting
1/1 instances: 1 running
OK</code></pre>
</div>
</div>
<div class="paragraph">
<p>The application is now available at the configured location! Under the url <code><a href="http://snifftest.a1-app.cf-app.com/" class="bare">http://snifftest.a1-app.cf-app.com/</a></code> in this particular example.</p>
</div>
</div>
<div class="sect3">
<h4 id="cloudfoundry-acknowledgements"><a class="anchor" href="#cloudfoundry-acknowledgements"></a><a class="link" href="#cloudfoundry-acknowledgements">Acknowledgements</a></h4>
<div class="paragraph">
<p>The Jetty buildpack was forked from the CloudFoundry Java buildpack. The Virgo Buildpack that Glyn worked on was used as a sanity check.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="http://github.com/cloudfoundry/cloudfoundry-buildpack-java" class="bare">http://github.com/cloudfoundry/cloudfoundry-buildpack-java</a></p>
</li>
<li>
<p><a href="http://github.com/glyn/virgo-buildpack" class="bare">http://github.com/glyn/virgo-buildpack</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>CloudFoundry buildpacks were modelled on Heroku buildpacks.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="elastic-beanstalk"><a class="anchor" href="#elastic-beanstalk"></a><a class="link" href="#elastic-beanstalk">Amazon Elastic Beanstalk</a></h3>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
This is an increasingly aged integration, things like likely changed enough this is not directly useful but may serve as a useful starting point should someone want to look into it.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p><a href="http://aws.amazon.com/elasticbeanstalk/">Elastic Beanstalk</a> is a component with the <a href="http://aws.amazon.com">Amazon Web Services</a> offering that allows you to configure an entire virtual machine based on one of several available baseline configurations and then customize it through a powerful configuration system. While the default offerings currently available are based on Tomcat for for the java community, we worked out the basics using that configuration system to enable the usage of Jetty instead.</p>
</div>
<div class="sect3">
<h4 id="elastic-beanstalk-overview"><a class="anchor" href="#elastic-beanstalk-overview"></a><a class="link" href="#elastic-beanstalk-overview">Overview</a></h4>
<div class="paragraph">
<p>Elastic beanstalk has a very <a href="http://aws.amazon.com/about-aws/whats-new/2012/10/02/introducing-aws-elastic-beanstalk-configuration-files/">powerful configuration mechanism</a> so this integration taps into that to effectively rework the tomcat configuration and replace it with the bits required to make jetty run in its place. Below is a walk through of what the various configuration files are doing and how the general flow of configuration on beanstalk happens.</p>
</div>
<div class="paragraph">
<p>There is an <code>.ebextensions</code> directory in your beanstalk application which contains all of the files requires to configure and customize your beanstalk and application combo.
Files that end in .config in this directory are processed in alphabetical order.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">00-java7.config</dt>
<dd>
<p>installs java 7 onto the beanstalk environment and makes it the default</p>
</dd>
<dt class="hdlist1">10-tweak.config</dt>
<dd>
<p>not required, but changes the <code>/opt/elasticbeanstalk</code> directory to be readable making debugging easier</p>
</dd>
<dt class="hdlist1">11-jetty.config</dt>
<dd>
<p>installs jetty9 into <code>/opt/jetty-9</code> and removes unneeded distribution files</p>
</dd>
<dt class="hdlist1">12-beanstalk.config</dt>
<dd>
<p>handles replacing tomcat with jetty in many configuration files, configures logging and wires up system startup processes.
Some files in your <code>.ebextensions</code> directory are moved to replace files under /opt/elasticbeanstalk.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>If you look in the <code>.ebextensions</code> directory of your application you should also see other jetty specific xml and ini files.
The final config file handles these as they are largely customization for your application.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">20-testapp.config</dt>
<dd>
<p>layers application specific configuration files into the jetty installation</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>The files in our example test webapp here enable various OPTIONS for libraries that need to be loaded, customize the root application being deployed and even deploy additional contexts like we do in our jetty distribution demo.
This is also the mechanism that you would use to wire up application specific things, for example if you needed additional software installed, customized directories made, etc.</p>
</div>
</div>
<div class="sect3">
<h4 id="elastic-beanstalk-maven"><a class="anchor" href="#elastic-beanstalk-maven"></a><a class="link" href="#elastic-beanstalk-maven">Maven Bits</a></h4>
<div class="paragraph">
<p>Support for this feature leverages Maven to make things easy and is composed of three different modules.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty-beanstalk-overlay</dt>
<dd>
<p>This is the collection of scripts that are required to wedge jetty into the normal beanstalk setup.
This module is intended to extract into an webapp to enable it for beanstalk usage with jetty.</p>
</dd>
<dt class="hdlist1">jetty-beanstalk-resources</dt>
<dd>
<p>This generates an artifact of files that are downloaded by the configuration process and contains replacements for certain beanstalk files as well as various system level jetty configuration files like an updated <code>jetty.sh</code> script for the <code>/etc/init.d</code> setup.</p>
</dd>
<dt class="hdlist1">jetty-beanstalk-testapp</dt>
<dd>
<p>An example webapp that shows both how to combine the war file from another maven module with the jetty-beanstalk-overlay to produce a beanstalk enabled application bundle.
Also included is examples of how to alter the jetty configuration for things like a customized
<code>start.ini</code> file.</p>
</dd>
</dl>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The test webapps needs access to a snapshot version of the test-jetty-webapp so it really serves as more of an example of how to layer your webapp with the bits required to customize your app for beanstalk and jetty.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>To actually make use of these artifacts you currently must clone this git repository and build it locally.
Once you have the artifacts you simply need to copy the approach in the jetty-beanstalk-testapp to apply the configuration to your webapp.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://github.com/jmcc0nn3ll/jetty-beanstalk" class="bare">https://github.com/jmcc0nn3ll/jetty-beanstalk</a></p>
</li>
</ul>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
Bluepill is used to manage the start and stop process of the app server.
This seems to be a problematic bit of software with a colored history and the version in use at the time of this writing is old.
When starting and stopping (or restarting) the appserver you may see error messages show up that the Server timed out getting a response or things like that.
These are red herrings and my experience is that jetty has started and stopped just fine, the pid file required shows up in a very timely fashion (under <code>/var/run/jetty.pid</code>) so do check that the app server has started, but please be aware there is a strangeness here that hasn&#8217;t been sorted out yet.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
</div>
<div class="sect2">
<h3 id="fedora"><a class="anchor" href="#fedora"></a><a class="link" href="#fedora">Fedora</a></h3>
<div class="paragraph">
<p>As of Fedora 19, Jetty 9 is the version of Jetty available.
This distribution of Jetty is not created or maintained by the Jetty project though we have had a fair amount of communication with the folks behind it and we are very pleased with how this Linux distribution has stayed current.
Releases are kept largely in sync with our releases as there is a wonderful automatic notification mechanism in place for Fedora that detects our releases and immediately opens an issue for them to update.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://admin.fedoraproject.org/pkgdb/acls/name/jetty">Jetty on Fedora</a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="ubuntu"><a class="anchor" href="#ubuntu"></a><a class="link" href="#ubuntu">Ubuntu</a></h3>
<div class="paragraph">
<p>Currently there are no actual <code>.deb</code> files available for installing on Debian based Linux machines but there is a handy blog that as been largely been kept up to date on the steps involved through the comments.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="http://pietervogelaar.nl/ubuntu-12-04-install-jetty-9/">Install Jetty9
on Ubuntu</a></p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="runner"><a class="anchor" href="#runner"></a><a class="link" href="#runner">Jetty Runner</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>This chapter explains how to use the <code>jetty-runner</code> to run your webapps without needing an installation of Jetty.</p>
</div>
<div class="sect2">
<h3 id="jetty-runner"><a class="anchor" href="#jetty-runner"></a><a class="link" href="#jetty-runner">Use Jetty Without an Installed Distribution</a></h3>
<div class="paragraph">
<p>The idea of the <code>jetty-runner</code> is extremely simple – run a webapp directly from the command line using a single jar file and as much default configuration as possible.
Of course, if your webapp is not as straightforward, the <code>jetty-runner</code> has command line options which allow you to customize the execution environment.</p>
</div>
<div class="sect3">
<h4 id="jetty-runner-preparation"><a class="anchor" href="#jetty-runner-preparation"></a><a class="link" href="#jetty-runner-preparation">Preparation</a></h4>
<div class="paragraph">
<p>You will need the <code>jetty-runner</code> jar:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Download the <code>jetty-runner</code> jar available at <a href="https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-runner/">Maven Central</a>.</p>
</li>
</ol>
</div>
</div>
<div class="sect3">
<h4 id="_deploying-a-simple-context"><a class="anchor" href="#_deploying-a-simple-context"></a><a class="link" href="#_deploying-a-simple-context">Deploying a Simple Context</a></h4>
<div class="paragraph">
<p>Let&#8217;s assume we have a very simple webapp that does not need any resources from its environment, nor any configuration apart from the defaults.
Starting it is as simple as performing the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar simple.war</code></pre>
</div>
</div>
<div class="paragraph">
<p>This will start Jetty on port 8080, and deploy the webapp to <code>/</code>.</p>
</div>
<div class="paragraph">
<p>Your webapp does not have to be packed into a war, you can deploy a webapp that is a directory instead in the same way:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar simple</code></pre>
</div>
</div>
<div class="paragraph">
<p>In fact, the webapp does not have to be a war or even a directory, it can simply be a Jetty <a href="#using-context-provider">context xml</a> file that describes your webapp:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar simple-context.xml</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
When using a context xml file, the application being deployed is not even required to be a fully-fledged webapp.
It can simply be a Jetty <a href="#what-is-a-context">context</a>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>By default, <code>jetty-runner</code> implements all Configuration Classes so that users can set up and deploy new instances with as little configuration as possible.
If you wish to only implement certain Configuration Classes, they will need to be defined in the context xml for the webapp/context.
The default Configuration Classes are:</p>
</div>
<div class="paragraph">
<p><code>org.eclipse.jetty.webapp.WebInfConfiguration</code>
<code>org.eclipse.jetty.webapp.WebXmlConfiguration</code>
<code>org.eclipse.jetty.webapp.MetaInfConfiguration</code>
<code>org.eclipse.jetty.webapp.FragmentConfiguration</code>
<code>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</code>
<code>org.eclipse.jetty.plus.webapp.EnvConfiguration</code>
<code>org.eclipse.jetty.plus.webapp.PlusConfiguration</code>
<code>org.eclipse.jetty.annotations.AnnotationConfiguration</code></p>
</div>
<div class="paragraph">
<p>You can learn more about implementing specific Configuration Classes <a href="https://www.eclipse.org/jetty/documentation/current/configuring-webapps.html#webapp-configurations">here.</a></p>
</div>
</div>
<div class="sect3">
<h4 id="_deploying-multiple-contexts"><a class="anchor" href="#_deploying-multiple-contexts"></a><a class="link" href="#_deploying-multiple-contexts">Deploying Multiple Contexts</a></h4>
<div class="paragraph">
<p>If you have more than one webapp that must be deployed, simply provide them all on the command line.
You can control the context paths for them using the <code>--path</code> parameter.
Here&#8217;s an example of deploying 2 wars (although either or both of them could be unpacked directories instead):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --path /one my1.war --path /two my2.war</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you have context xml files that describe your webapps, you can fully configure your webapps in them and hence you won&#8217;t need to use the command line switches.
Just provide the list of context files like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar my-first-context.xml my-second-context.xml my-third-context.xml</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Switched used on the command line override configuration file settings.
So, for example, you could set the context path for the webapp inside the context xml file, and use the <code>--path</code> switch to override it on the command line.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect4">
<h5 id="_changing-the-default-port"><a class="anchor" href="#_changing-the-default-port"></a><a class="link" href="#_changing-the-default-port">Changing the Default Port</a></h5>
<div class="paragraph">
<p>By default the <code>jetty-runner</code> will listen on port 8080.
You can easily change this on the command line using the <code>--port</code> command.
Here&#8217;s an example that runs our simple.war on port 9090:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --port 9090 simple.war</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_using-jetty-xml-files"><a class="anchor" href="#_using-jetty-xml-files"></a><a class="link" href="#_using-jetty-xml-files">Using jetty.xml Files</a></h5>
<div class="paragraph">
<p>Instead of, or in addition to, using command line switches, you can use one or more <code>jetty.xml</code> files to configure the environment for your webapps.
Here&#8217;s an example where we apply two different <code>jetty.xml</code> files:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --config jetty.xml --config jetty-https.xml simple.war</code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="runner-configuration-reference"><a class="anchor" href="#runner-configuration-reference"></a><a class="link" href="#runner-configuration-reference">Full Configuration Reference</a></h4>
<div class="paragraph">
<p>You can see the fill set of configuration options using the <code>--help</code> switch:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --help</code></pre>
</div>
</div>
<div class="paragraph">
<p>Here&#8217;s what the output will look like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="plain">Usage: java [-Djetty.home=dir] -jar jetty-runner.jar [--help|--version] [ server opts] [[ context opts] context ...]
Server opts:
--version - display version and exit
--log file - request log filename (with optional 'yyyy_mm_dd' wildcard
--out file - info/warn/debug log filename (with optional 'yyyy_mm_dd' wildcard
--host name|ip - interface to listen on (default is all interfaces)
--port n - port to listen on (default 8080)
--stop-port n - port to listen for stop command (or -DSTOP.PORT=n)
--stop-key n - security string for stop command (required if --stop-port is present) (or -DSTOP.KEY=n)
[--jar file]*n - each tuple specifies an extra jar to be added to the classloader
[--lib dir]*n - each tuple specifies an extra directory of jars to be added to the classloader
[--classes dir]*n - each tuple specifies an extra directory of classes to be added to the classloader
--stats [unsecure|realm.properties] - enable stats gathering servlet context
[--config file]*n - each tuple specifies the name of a jetty xml config file to apply (in the order defined)
Context opts:
[[--path /path] context]*n - WAR file, web app dir or context xml file, optionally with a context path</code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_printing-the-version"><a class="anchor" href="#_printing-the-version"></a><a class="link" href="#_printing-the-version">Printing the Version</a></h5>
<div class="paragraph">
<p>Print out the version of Jetty and then exit immediately.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --version</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_configuring-a-request-log"><a class="anchor" href="#_configuring-a-request-log"></a><a class="link" href="#_configuring-a-request-log">Configuring a Request Log</a></h5>
<div class="paragraph">
<p>Cause Jetty to write a request log with the given name.
If the file is prefixed with <code>yyyy_mm_dd</code> then the file will be automatically rolled over.
Note that for finer grained configuration of the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/NCSARequestLog.html">request log</a>, you will need to use a Jetty xml file instead.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --log yyyy_mm_dd-requests.log my.war</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_configuring-the-output-log"><a class="anchor" href="#_configuring-the-output-log"></a><a class="link" href="#_configuring-the-output-log">Configuring the Output Log</a></h5>
<div class="paragraph">
<p>Redirect the output of jetty logging to the named file.
If the file is prefixed with <code>yyyy_mm_dd</code> then the file will be automatically rolled over.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --out yyyy_mm_dd-output.log my.war</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_configuring-the-interface-for-http"><a class="anchor" href="#_configuring-the-interface-for-http"></a><a class="link" href="#_configuring-the-interface-for-http">Configuring the Interface for HTTP</a></h5>
<div class="paragraph">
<p>Like Jetty standalone, the default is for the connectors to listen on all interfaces on a machine.
You can control that by specifying the name or ip address of the particular interface you wish to use with the <code>--host</code> argument:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --host 192.168.22.19 my.war</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_configuring-the-port-for-http"><a class="anchor" href="#_configuring-the-port-for-http"></a><a class="link" href="#_configuring-the-port-for-http">Configuring the Port for HTTP</a></h5>
<div class="paragraph">
<p>The default port number is 8080.
To <a href="#how-to-configure-connectors">configure a https connector</a>, use a Jetty xml config file instead.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --port 9090 my.war</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_configuring-stop"><a class="anchor" href="#_configuring-stop"></a><a class="link" href="#_configuring-stop">Configuring Stop</a></h5>
<div class="paragraph">
<p>You can configure a port number for Jetty to listen on for a stop command, so you are able to stop it from a different terminal.
This requires the use of a "secret" key, to prevent malicious or accidental termination.
Use the <code>--stop-port</code> and <code>--stop-key</code> (or <code>-DSTOP.PORT=</code> and <code>-DSTOP.KEY=</code>, respectively) parameters as arguments to the <code>jetty-runner</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --stop-port 8181 --stop-key abc123</code></pre>
</div>
</div>
<div class="paragraph">
<p>Then, to stop Jetty from a different terminal, you need to supply the same port and key information.
For this you&#8217;ll either need a local installation of Jetty, the <a href="#jetty-maven-plugin">jetty-maven-plugin</a>, the <a href="#jetty-ant">jetty-ant plugin</a>, or a custom class.
Here&#8217;s how to use a Jetty installation to perform a stop:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar start.jar -DSTOP.PORT=8181 -DSTOP.KEY=abc123 --stop</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_configuring-the-container-classpath"><a class="anchor" href="#_configuring-the-container-classpath"></a><a class="link" href="#_configuring-the-container-classpath">Configuring the Container Classpath</a></h5>
<div class="paragraph">
<p>With a local installation of Jetty, you add jars and classes to the container&#8217;s classpath by putting them in the <code>{$jetty.base}/lib</code> directory.
With the <code>jetty-runner</code>, you can use the <code>--lib</code>, <code>--jar</code> and <code>--classes</code> arguments instead to achieve the same thing.</p>
</div>
<div class="paragraph">
<p><code>--lib</code> adds the location of a directory which contains jars to add to the container classpath.
You can add 1 or more.
Here&#8217;s an example of configuring 2 directories:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --lib /usr/local/external/lib --lib $HOME/external-other/lib my.war</code></pre>
</div>
</div>
<div class="paragraph">
<p><code>--jar</code> adds a single jar file to the container classpath.
You can add 1 or more.
Here&#8217;s an example of configuring 3 extra jars:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --jar /opt/stuff/jars/jar1.jar --jar $HOME/jars/jar2.jar --jar /usr/local/proj/jars/jar3.jar my.war</code></pre>
</div>
</div>
<div class="paragraph">
<p><code>--classes</code> add the location of a directory containing classes to add to the container classpath.
You can add 1 or more.
Here&#8217;s an example of configuring a single extra classes dir:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --classes /opt/stuff/classes my.war</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
When using the <code>--jar</code> and/or <code>--lib</code> arguments, by default these will <strong>not</strong> be inspected for <code>META-INF</code> information such as <code>META-INF/resources</code>, <code>META-INF/web-fragment.xml</code>, or <code>META-INF/taglib.tld</code>.
If you require these jar files inspected you will need to define the <a href="https://www.eclipse.org/jetty/documentation/current/configuring-webapps.html#webapp-context-attributes">jar pattern in your context xml file</a>.
Jetty-Runner automatically provides and appends a suitable pattern for jtsl taglibs (this pattern is different than the one in the standard Jetty distribution).
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect4">
<h5 id="_gathering-statistics"><a class="anchor" href="#_gathering-statistics"></a><a class="link" href="#_gathering-statistics">Gathering Statistics</a></h5>
<div class="paragraph">
<p>If statistics gathering is enabled, then they are viewable by surfing to the context <code>/stats</code>.
You may optionally protect access to that context with a password.
Here&#8217;s an example of enabling statistics, with no password protection:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --stats unsecure my.war</code></pre>
</div>
</div>
<div class="paragraph">
<p>If we wished to protect access to the <code>/stats</code> context, we would provide the location of a Jetty realm configuration file containing authentication and authorization information.
For example, we could use the following example realm file from the Jetty distribution:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">jetty: MD5:164c88b302622e17050af52c89945d44,user
admin: CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin
other: OBF:1xmk1w261u9r1w1c1xmq,user
plain: plain,user
user: password,user
# This entry is for digest auth. The credential is a MD5 hash of username:realmname:password
digest: MD5:6e120743ad67abfbc385bc2bb754e297,user</code></pre>
</div>
</div>
<div class="paragraph">
<p>Assuming we&#8217;ve copied it into the local directory, we would apply it like so</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">&gt; java -jar jetty-runner.jar --stats realm.properties my.war</code></pre>
</div>
</div>
<div class="paragraph">
<p>After navigating to <a href="http://localhost:8080/" class="bare">http://localhost:8080/</a> a few times, we can point to the stats servlet on <a href="http://localhost:8080/stats" class="bare">http://localhost:8080/stats</a> to see the output:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>Statistics:
Statistics gathering started 1490627ms ago
Requests:
Total requests: 9
Active requests: 1
Max active requests: 1
Total requests time: 63
Mean request time: 7.875
Max request time: 26
Request time standard deviation: 8.349764752888037
Dispatches:
Total dispatched: 9
Active dispatched: 1
Max active dispatched: 1
Total dispatched time: 63
Mean dispatched time: 7.875
Max dispatched time: 26
Dispatched time standard deviation: 8.349764752888037
Total requests suspended: 0
Total requests expired: 0
Total requests resumed: 0
Responses:
1xx responses: 0
2xx responses: 7
3xx responses: 1
4xx responses: 0
5xx responses: 0
Bytes sent total: 1453
Connections:
org.eclipse.jetty.server.ServerConnector@203822411
Protocols:http/1.1
Statistics gathering started 1490606ms ago
Total connections: 7
Current connections open: 1
Max concurrent connections open: 2
Total connections duration: 72883
Mean connection duration: 12147.166666666666
Max connection duration: 65591
Connection duration standard deviation: 23912.40292977684
Total messages in: 7
Total messages out: 7
Memory:
Heap memory usage: 49194840 bytes
Non-heap memory usage: 12611696 bytes</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="configuring-security"><a class="anchor" href="#configuring-security"></a><a class="link" href="#configuring-security">Configuring Security</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="configuring-security-authentication"><a class="anchor" href="#configuring-security-authentication"></a><a class="link" href="#configuring-security-authentication">Authentication and Authorization</a></h3>
<div class="paragraph">
<p>There are two aspects to securing a web application(or context) within the Jetty server:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Authentication</dt>
<dd>
<p>The web application can be configured with a mechanism to determine the identity of the user.
This is configured by a mix of standard declarations and jetty specific mechanisms and is covered in this section.</p>
</dd>
<dt class="hdlist1">Authorization</dt>
<dd>
<p>Once the identify of the user is known (or not known), the web application can be configured via standard descriptors with security constraints that declare what resources that user may access.</p>
</dd>
</dl>
</div>
<div class="sect3">
<h4 id="_configuring-an-authentication-mechanism"><a class="anchor" href="#_configuring-an-authentication-mechanism"></a><a class="link" href="#_configuring-an-authentication-mechanism">Configuring an Authentication mechanism</a></h4>
<div class="paragraph">
<p>Jetty server supports several standard authentication mechanisms: <a href="http://en.wikipedia.org/wiki/Basic_access_authentication">BASIC</a>; <a href="http://en.wikipedia.org/wiki/Digest_authentication">DIGEST</a>; <a href="http://en.wikipedia.org/wiki/Form-based_authentication">FORM</a>; CLIENT-CERT; and other mechanisms can be plugged in using the extensible <a href="http://docs.oracle.com/cd/E19462-01/819-6717/gcszc/index.html">JASPI</a> or <a href="http://en.wikipedia.org/wiki/SPNEGO">SPNEGO</a> mechanisms.</p>
</div>
<div class="paragraph">
<p>Internally, configuring an authentication mechanism is done by setting an instance of a the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/security/Authenticator.html">Authenticator</a> interface onto the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/security/SecurityHandler.html">SecurityHandler</a> of the context, but in most cases it is done by declaring a <code>&lt;login-config&gt;</code> element in the standard web.xml descriptor or via annotations.</p>
</div>
<div class="paragraph">
<p>Below is an example taken from the <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/tests/test-webapps/test-jetty-webapp/src/main/webapp/WEB-INF/web.xml?h=release-9">jetty-test-webapp web.xml</a> that configures BASIC authentication:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;login-config&gt;</span>
<span class="tag">&lt;auth-method&gt;</span>BASIC<span class="tag">&lt;/auth-method&gt;</span>
<span class="tag">&lt;realm-name&gt;</span>Test Realm<span class="tag">&lt;/realm-name&gt;</span>
<span class="tag">&lt;/login-config&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/tests/test-webapps/test-jetty-webapp/src/main/webapp/WEB-INF/web.xml?h=release-9">jetty-test-webapp web.xml</a> also includes commented out examples of other DIGEST and FORM configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;login-config&gt;</span>
<span class="tag">&lt;auth-method&gt;</span>FORM<span class="tag">&lt;/auth-method&gt;</span>
<span class="tag">&lt;realm-name&gt;</span>Test Realm<span class="tag">&lt;/realm-name&gt;</span>
<span class="tag">&lt;form-login-config&gt;</span>
<span class="tag">&lt;form-login-page&gt;</span>/logon.html?param=test<span class="tag">&lt;/form-login-page&gt;</span>
<span class="tag">&lt;form-error-page&gt;</span>/logonError.html?param=test<span class="tag">&lt;/form-error-page&gt;</span>
<span class="tag">&lt;/form-login-config&gt;</span>
<span class="tag">&lt;/login-config&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>With FORM Authentication, you must also configure URLs of pages to generate a login form and handle errors.
Below is a simple HTML form from the <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/tests/test-webapps/test-jetty-webapp/src/main/webapp/logon.html?h=release-9">test webapp logon.html</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;HTML&gt;</span>
<span class="tag">&lt;H1&gt;</span>FORM Authentication demo<span class="tag">&lt;/H1&gt;</span>
<span class="tag">&lt;form</span> <span class="attribute-name">method</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">POST</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">action</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">j_security_check</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;table</span> <span class="attribute-name">border</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">0</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">cellspacing</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">2</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">cellpadding</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">1</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;tr&gt;</span>
<span class="tag">&lt;td&gt;</span>Username:<span class="tag">&lt;/td&gt;</span>
<span class="tag">&lt;td&gt;</span><span class="tag">&lt;input</span> <span class="attribute-name">size</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">12</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">j_username</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">maxlength</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">25</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">text</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;/td&gt;</span>
<span class="tag">&lt;/tr&gt;</span>
<span class="tag">&lt;tr&gt;</span>
<span class="tag">&lt;td&gt;</span>Password:<span class="tag">&lt;/td&gt;</span>
<span class="tag">&lt;td&gt;</span><span class="tag">&lt;input</span> <span class="attribute-name">size</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">12</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">j_password</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">maxlength</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">25</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;/td&gt;</span>
<span class="tag">&lt;/tr&gt;</span>
<span class="tag">&lt;tr&gt;</span>
<span class="tag">&lt;td</span> <span class="attribute-name">colspan</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">2</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">align</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">center</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;input</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">submit</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">submit</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Login</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;/td&gt;</span>
<span class="tag">&lt;/tr&gt;</span>
<span class="tag">&lt;/table&gt;</span>
<span class="tag">&lt;/form&gt;</span>
<span class="tag">&lt;/HTML&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The Authentication mechanism declared for a context / web application defines how the server obtain authentication credentials from the
client, but it does not define how the server checks if those credentials are valid.
To check credentials, the server and/or context also need to be configured with a <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/security/LoginService.html">LoginService</a> instance, which may be matched by the declared realm-name.</p>
</div>
</div>
<div class="sect3">
<h4 id="security-realms"><a class="anchor" href="#security-realms"></a><a class="link" href="#security-realms">Security Realms</a></h4>
<div class="paragraph">
<p>Security realms allow you to secure your web applications against unauthorized access.
Protection is based on authentication that identifies who is requesting access to the webapp and access control that restricts what can be accessed and how it is accessed within the webapp.</p>
</div>
<div class="paragraph">
<p>A webapp statically declares its security requirements in its web.xml file.
Authentication is controlled by the <code>&lt;login-config&gt;</code> element.
Access controls are specified by <code>&lt;security-constraint&gt;</code> and <code>&lt;security-role-ref&gt;</code> elements.
When a request is received for a protected resource, the web container checks if the user performing the request is authenticated, and if the user has a role assignment that permits access to the requested resource.</p>
</div>
<div class="paragraph">
<p>The Servlet Specification does not address how the static security information in the <code>WEB-INF/web.xml</code> file is mapped to the runtime environment of the container.
For Jetty, the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/security/LoginService.html">LoginService</a> performs this function.</p>
</div>
<div class="paragraph">
<p>A <code>LoginService</code> has a unique name, and gives access to information about a set of users.
Each user has authentication information (e.g. a password) and a set of roles associated with him/herself.</p>
</div>
<div class="paragraph">
<p>You may configure one or many different LoginServices depending on your needs.
A single realm would indicate that you wish to share common security information across all of your web applications.
Distinct realms allow you to partition your security information webapp by webapp.</p>
</div>
<div class="paragraph">
<p>When a request to a web application requires authentication or authorization, Jetty will use the <code>&lt;realm-name&gt;</code> sub-element inside <code>&lt;login-config&gt;</code> element in the web.xml file to perform an <em>exact match</em> to a LoginService.</p>
</div>
</div>
<div class="sect3">
<h4 id="_scoping-security-realms"><a class="anchor" href="#_scoping-security-realms"></a><a class="link" href="#_scoping-security-realms">Scoping Security Realms</a></h4>
<div class="paragraph">
<p>A <code>LoginService</code> has a unique name, and is composed of a set of users.
Each user has authentication information (for example, a password) and a set of roles associated with him/herself.
You can configure one or many different realms depending on your needs.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Configure a single LoginService to share common security information across all of your web applications.</p>
</li>
<li>
<p>Configure distinct LoginServices to partition your security information webapp by webapp.</p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="_globally-scoped"><a class="anchor" href="#_globally-scoped"></a><a class="link" href="#_globally-scoped">Globally Scoped</a></h5>
<div class="paragraph">
<p>A LoginService is available to all web applications on a Server instance if you add it as a bean to the Server.
Such a definition would go into an xml file in your <code>${jetty.base}/etc</code> directory, e.g. <code>${jetty.base}/etc/my-realm.xml</code> and you would add this xml file to the execution path via <code>start.ini</code> or <code>start.d</code> (you may want to review the material in the <a href="#startup">Starting Jetty</a> chapter).
Here&#8217;s an example of an xml file that defines an in-memory type of LoginService called the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/security/HashLoginService.html">HashLoginService</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addBean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.HashLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">config</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/etc/realm.properties<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">hotReload</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>If you define more than one <code>LoginService</code> on a Server, you will need to specify which one you want used for each context.
You can do that by telling the context the name of the <code>LoginService</code>, or passing it the <code>LoginService</code> instance.
Here&#8217;s an example of doing both of these, using a <a href="#deployable-descriptor-file">context xml file</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Get</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">securityHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="comment">&lt;!-- Either: --&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">loginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.HashLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="comment">&lt;!-- or if you defined a LoginService called &quot;Test Realm&quot; in jetty.xml : --&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">realmName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Get&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_per-webapp-scoped"><a class="anchor" href="#_per-webapp-scoped"></a><a class="link" href="#_per-webapp-scoped">Per-Webapp Scoped</a></h5>
<div class="paragraph">
<p>Alternatively, you can define a <code>LoginService</code> for just a single web application.
Here&#8217;s how to define the same HashLoginService, but inside a <a href="#deployable-descriptor-file">context xml file</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/test<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/webapps/test<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Get</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">securityHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">loginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.HashLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">config</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/etc/realm.properties<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Get&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Jetty provides a number of different <code>LoginService</code> types which can be seen in the next section.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="configuring-login-service"><a class="anchor" href="#configuring-login-service"></a><a class="link" href="#configuring-login-service">Configuring a LoginService</a></h4>
<div class="paragraph">
<p>A <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/security/LoginService.html"><code>LoginService</code></a> instance is required by each context/webapp that has a authentication mechanism, which is used to check the validity of the username and credentials collected by the authentication mechanism. Jetty provides the following implementations of <code>LoginService</code>:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/security/HashLoginService.html">HashLoginService</a></dt>
<dd>
<p>A user realm that is backed by a hash map that is filled either programatically or from a Java properties file.</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/security/JDBCLoginService.html">JDBCLoginService</a></dt>
<dd>
<p>Uses a JDBC connection to an SQL database for authentication</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/plus/security/DataSourceLoginService.html">DataSourceLoginService</a></dt>
<dd>
<p>Uses a JNDI defined <a href="http://docs.oracle.com/javase/7/docs/api/javax/sql/DataSource.html">DataSource</a> for authentication</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/jaas/JAASLoginService.html">JAASLoginService</a></dt>
<dd>
<p>Uses a <a href="http://en.wikipedia.org/wiki/Java_Authentication_and_Authorization_Service">JAAS</a> provider for authentication; see the section on
<a href="#jaas-support">JAAS support</a> for more information</p>
</dd>
<dt class="hdlist1"><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/security/SpnegoLoginService.html">SpnegoLoginService</a></dt>
<dd>
<p><a href="http://en.wikipedia.org/wiki/SPNEGO">SPNEGO</a> Authentication; see the section on <a href="#spnego-support">SPNEGO support</a> for more information.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>An instance of a <code>LoginService</code> can be matched to a context/webapp by:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A <code>LoginService</code> instance may be set directly on the <code>SecurityHandler</code> instance via embedded code or IoC XML</p>
</li>
<li>
<p>Matching the realm-name defined in web.xml with the name of a <code>LoginService</code> instance that has been added to the Server instance as a dependent bean</p>
</li>
<li>
<p>If only a single <code>LoginService</code> instance has been set on the Server then it is used as the login service for the context</p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="hash-login-service"><a class="anchor" href="#hash-login-service"></a><a class="link" href="#hash-login-service">HashLoginService</a></h5>
<div class="paragraph">
<p>The <code>HashLoginService</code> is a simple and efficient login service that loads usernames, credentials and roles from a Java properties file in the format:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="properties">username: password[,rolename ...]</code></pre>
</div>
</div>
<div class="paragraph">
<p>Where:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">username</dt>
<dd>
<p>is the user&#8217;s unique identity</p>
</dd>
<dt class="hdlist1">password</dt>
<dd>
<p>is the user&#8217;s (possibly obfuscated or MD5 encrypted) password;</p>
</dd>
<dt class="hdlist1">rolename</dt>
<dd>
<p>is a role of the user</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="properties">admin: CRYPT:ad1ks..kc.1Ug,server-administrator,content-administrator,admin
other: OBF:1xmk1w261u9r1w1c1xmq
guest: guest,read-only</code></pre>
</div>
</div>
<div class="paragraph">
<p>You configure the <code>HashLoginService</code> with a name and a reference to the location of the properties file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Item&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.HashLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">config</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/etc/realm.properties<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Item&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>You can also configure it to reload the configuration file when changes to it are detected.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.HashLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">config</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;SystemProperty</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jetty.home</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">default</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">.</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>/etc/realm.properties<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">hotReload</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">start</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="jdbc-login-service"><a class="anchor" href="#jdbc-login-service"></a><a class="link" href="#jdbc-login-service">JDBCLoginService</a></h5>
<div class="paragraph">
<p>In this implementation, authentication and role information is stored in a database accessed via JDBC.
A properties file defines the JDBC connection and database table information.
Here is an example of a properties file for this realm implementation:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="properties">jdbcdriver = org.gjt.mm.mysql.Driver
url = jdbc:mysql://localhost/jetty
username = jetty
password = jetty
usertable = users
usertablekey = id
usertableuserfield = username
usertablepasswordfield = pwd
roletable = roles
roletablekey = id
roletablerolefield = role
userroletable = user_roles
userroletableuserkey = user_id
userroletablerolekey = role_id
cachetime = 300</code></pre>
</div>
</div>
<div class="paragraph">
<p>The format of the database tables is (pseudo-sql):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">users
(
id <span class="predefined-type">integer</span> <span class="directive">PRIMARY</span> <span class="type">KEY</span>,
username <span class="predefined-type">varchar</span>(<span class="integer">100</span>) <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span> <span class="directive">UNIQUE</span> <span class="type">KEY</span>,
pwd <span class="predefined-type">varchar</span>(<span class="integer">50</span>) <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
);
user_roles
(
user_id <span class="predefined-type">integer</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>,
role_id <span class="predefined-type">integer</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>,
<span class="directive">UNIQUE</span> <span class="type">KEY</span> (user_id, role_id),
<span class="type">INDEX</span>(user_id)
);
roles
(
id <span class="predefined-type">integer</span> <span class="directive">PRIMARY</span> <span class="type">KEY</span>,
role <span class="predefined-type">varchar</span>(<span class="integer">100</span>) <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span> <span class="directive">UNIQUE</span> <span class="type">KEY</span>
);</code></pre>
</div>
</div>
<div class="paragraph">
<p>Where:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><strong>users</strong> is a table containing one entry for every user consisting of:</p>
<div class="dlist">
<dl>
<dt class="hdlist1">id</dt>
<dd>
<p>the unique identity of a user</p>
</dd>
<dt class="hdlist1">user</dt>
<dd>
<p>the name of the user</p>
</dd>
<dt class="hdlist1">pwd</dt>
<dd>
<p>the user&#8217;s password (possibly obfuscated or MD5 encrypted)</p>
</dd>
</dl>
</div>
</li>
<li>
<p><strong>user-roles</strong> is a table containing one row for every role granted to a
user:</p>
<div class="dlist">
<dl>
<dt class="hdlist1">user_id</dt>
<dd>
<p>the unique identity of the user</p>
</dd>
<dt class="hdlist1">role_id</dt>
<dd>
<p>the role for a user</p>
</dd>
</dl>
</div>
</li>
<li>
<p><strong>roles</strong> is a a table containing one role for every role in the system:</p>
<div class="dlist">
<dl>
<dt class="hdlist1">id</dt>
<dd>
<p>the unique identifier of a role</p>
</dd>
<dt class="hdlist1">role</dt>
<dd>
<p>a human-readable name for a role</p>
</dd>
</dl>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>If you want to use obfuscated, MD5 hashed or encrypted passwords the <code>pwd</code> column of the <code>users</code> table must be large enough to hold the obfuscated, hashed or encrypted password text plus the appropriate prefix.</p>
</div>
<div class="paragraph">
<p>You define a <code>JDBCLoginService</code> with the name of the realm and the location of the properties file describing the database:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.JDBCLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test JDBC Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">config</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>etc/jdbcRealm.properties<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_authorization"><a class="anchor" href="#_authorization"></a><a class="link" href="#_authorization">Authorization</a></h4>
<div class="paragraph">
<p>As far as the <a href="https://jcp.org/en/jsr/detail?id=340">Servlet Specification</a> is concerned, authorization is based on roles.
As we have seen, a <code>LoginService</code> associates a user with a set of roles.
When a user requests a resource that is access protected, the <code>LoginService</code> will be asked to authenticate the user if they are not already, and then asked to confirm if that user possesses one of the roles permitted access to the resource.</p>
</div>
<div class="paragraph">
<p>Until Servlet 3.1, role-based authorization could define:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Access granted to a set of named roles:</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;security-constraint&gt;</span>
<span class="tag">&lt;web-resource-collection&gt;</span>
<span class="tag">&lt;web-resource-name&gt;</span>Foo Admin Data<span class="tag">&lt;/web-resource-name&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>/foo/admin/*<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;/web-resource-collection&gt;</span>
<span class="tag">&lt;auth-constraint&gt;</span>
<span class="tag">&lt;role-name&gt;</span>admin<span class="tag">&lt;/role-name&gt;</span>
<span class="tag">&lt;role-name&gt;</span>manager<span class="tag">&lt;/role-name&gt;</span>
<span class="tag">&lt;/auth-constraint&gt;</span>
<span class="tag">&lt;/security-constraint&gt;</span></code></pre>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>Access totally forbidden, regardless of role:</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;security-constraint&gt;</span>
<span class="tag">&lt;web-resource-collection&gt;</span>
<span class="tag">&lt;web-resource-name&gt;</span>Foo Protected Data<span class="tag">&lt;/web-resource-name&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>/foo/protected/*<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;/web-resource-collection&gt;</span>
<span class="tag">&lt;auth-constraint&gt;</span>
<span class="tag">&lt;/auth-constraint&gt;</span>
<span class="tag">&lt;/security-constraint&gt;</span></code></pre>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>Access granted to a user in any of the roles defined in the effective <code>web.xml</code>.
This is indicated by the special value of <code>*</code> for the <code>&lt;role-name&gt;</code> of a <code>&lt;auth-constraint&gt;</code> in the <code>&lt;security-constraint&gt;</code>:</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;security-constraint&gt;</span>
<span class="tag">&lt;web-resource-collection&gt;</span>
<span class="tag">&lt;web-resource-name&gt;</span>Foo Role Data<span class="tag">&lt;/web-resource-name&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>/foo/role/*<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;/web-resource-collection&gt;</span>
<span class="tag">&lt;auth-constraint&gt;</span>
<span class="tag">&lt;role-name&gt;</span>*<span class="tag">&lt;/role-name&gt;</span>
<span class="tag">&lt;/auth-constraint&gt;</span>
<span class="tag">&lt;/security-constraint&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Servlet 3.1 introduced an additional authorization:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Access granted to any user who is authenticated, regardless of roles.
This is indicated by the special value of <code>**</code> for the <code>&lt;role-name&gt;</code> of a <code>&lt;auth-constraint&gt;</code> in the <code>&lt;security-constraint&gt;</code>:</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;security-constraint&gt;</span>
<span class="tag">&lt;web-resource-collection&gt;</span>
<span class="tag">&lt;web-resource-name&gt;</span>Foo Authenticated Data<span class="tag">&lt;/web-resource-name&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>/foo/authenticated/*<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;/web-resource-collection&gt;</span>
<span class="tag">&lt;auth-constraint&gt;</span>
<span class="tag">&lt;role-name&gt;</span>**<span class="tag">&lt;/role-name&gt;</span>
<span class="tag">&lt;/auth-constraint&gt;</span>
<span class="tag">&lt;/security-constraint&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Additionally, when configuring your security constraints you can protect various HTTP methods as well, such as <code>PUT</code>, <code>GET</code>, <code>POST</code>, <code>HEAD</code> or <code>DELETE</code>.
This is done by adding the method you want to protect as a <code>&lt;http-method&gt;</code> in the <code>&lt;web-resource-collection&gt;</code>.
You can then define roles that should be able to perform these protected methods in an <code>&lt;auth-constraint&gt;</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;security-constraint&gt;</span>
<span class="tag">&lt;web-resource-collection&gt;</span>
<span class="tag">&lt;web-resource-name&gt;</span>Foo Authenticated Data<span class="tag">&lt;/web-resource-name&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>/foo/authenticated/*<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;http-method&gt;</span>DELETE<span class="tag">&lt;/http-method&gt;</span>
<span class="tag">&lt;http-method&gt;</span>POST<span class="tag">&lt;/http-method&gt;</span>
<span class="tag">&lt;/web-resource-collection&gt;</span>
<span class="tag">&lt;auth-constraint&gt;</span>
<span class="tag">&lt;role-name&gt;</span>admin<span class="tag">&lt;/role-name&gt;</span>
<span class="tag">&lt;/auth-constraint&gt;</span>
<span class="tag">&lt;/security-constraint&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>In the above example, only users with an <code>admin</code> role will be able to perform <code>DELETE</code> or <code>POST</code> methods.</p>
</div>
<div class="sect4">
<h5 id="_configuring-authorization-with-context-xml-files"><a class="anchor" href="#_configuring-authorization-with-context-xml-files"></a><a class="link" href="#_configuring-authorization-with-context-xml-files">Configuring Authorization with Context XML Files</a></h5>
<div class="paragraph">
<p>While the examples above show configuration of Authorization in a <code>web.xml</code> file, they can also be configured as part of the link#<a href="#deployable-descriptor-file">context xml file</a> for a web application.
This is especially helpful if authorization needs change over time and need updated without re-packaging the whole web app.</p>
</div>
<div class="paragraph">
<p>To do this, we add a section for security constraints into the context xml file for our web app as part of the <code>securityHandler</code>.
In the example below, a <code>HashLoginService</code> is defined with authorization being granted too <code>foo/*</code> paths to users with the <code>admin</code> and <code>manager</code> roles.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">testWebapp</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Get</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">securityHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">realmName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">authMethod</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>BASIC<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addConstraintMapping</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.ConstraintMapping</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">pathSpec</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/foo/*<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">constraint</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.util.security.Constraint</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Foo Auth<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">authenticate</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">roles</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.lang.String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Item&gt;</span>admin<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;Item&gt;</span>manager<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">loginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.HashLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">config</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/src/tmp/small-security-test/realm.properties<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Get&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>If roles changed in the future, administrators could easily change this context xml file without having to edit the contents of the web app at all.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_authentication-and-authorization-with-embedded-jetty"><a class="anchor" href="#_authentication-and-authorization-with-embedded-jetty"></a><a class="link" href="#_authentication-and-authorization-with-embedded-jetty">Authentication and Authorization with Embedded Jetty</a></h4>
<div class="paragraph">
<p>In addition to the distribution, security can be defined as part of an embedded implementation as well.
Below is an example which, like the one above, sets up a server with a <code>HashLoginService</code> and adds security constraints to restrict access based on roles.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in security/authentication.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../examples/embedded/src/main/java/org/eclipse/jetty/embedded/SecuredHelloHandler.java<span class="type">[]</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_jsr-196-java-authentication-service-provider-interface-for-containers-jaspi"><a class="anchor" href="#_jsr-196-java-authentication-service-provider-interface-for-containers-jaspi"></a><a class="link" href="#_jsr-196-java-authentication-service-provider-interface-for-containers-jaspi">JSR 196: Java Authentication Service Provider Interface for Containers (JASPI)</a></h4>
<div class="paragraph">
<p>Jetty can utilize portable authentication modules that implements the Jakarta Authentication specification. This requires the jetty-jaspi module.</p>
</div>
<div class="paragraph">
<p>Only modules conforming to the ServerAuthModule interface in the <a href="https://www.jcp.org/en/jsr/detail?id=196">JASPI Spec</a> are supported. These modules must be configured before start-up.</p>
</div>
<div class="paragraph">
<p>The following illustrates a jetty module setting up HTTP Basic Authentication using an Authentication module that comes packaged with the jetty-jaspi module: <code>org.eclipse.jetty.security.jaspi.modules.BasicAuthenticationAuthModule</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml">Unresolved directive in security/authentication.adoc - include::/home/joakim/code/jetty/jetty.project-10.0.x/documentation/jetty-documentation/../jetty-jaspi/src/main/config/etc/jaspi/jaspi-demo.xml[tags=documentation]</code></pre>
</div>
</div>
<div class="paragraph">
<p>Given the portability goal of Jakarta Authentication, custom or 3rd party <code>ServerAuthModule</code> implementations may be configured instead here.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="configuring-form-size"><a class="anchor" href="#configuring-form-size"></a><a class="link" href="#configuring-form-size">Limiting Form Content</a></h3>
<div class="paragraph">
<p>Form content sent to the server is processed by Jetty into a map of parameters to be used by the web application.
This can be vulnerable to denial of service (DOS) attacks since significant memory and CPU can be consumed if a malicious clients sends very large form content or large number of form keys.
Thus Jetty limits the amount of data and keys that can be in a form posted to Jetty.</p>
</div>
<div class="paragraph">
<p>The default maximum size Jetty permits is 200000 bytes and 1000 keys.
You can change this default for a particular webapp or for all webapps on a particular Server instance.</p>
</div>
<div class="sect3">
<h4 id="_configuring-form-limits-for-a-webapp"><a class="anchor" href="#_configuring-form-limits-for-a-webapp"></a><a class="link" href="#_configuring-form-limits-for-a-webapp">Configuring Form Limits for a Webapp</a></h4>
<div class="paragraph">
<p>To configure the form limits for a single web application, the context handler (or webappContext) instance must be configured using the following methods:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">ContextHandler.setMaxFormContentSize(<span class="type">int</span> maxSizeInBytes);
ContextHandler.setMaxFormKeys(<span class="type">int</span> formKeys);</code></pre>
</div>
</div>
<div class="paragraph">
<p>These methods may be called directly when embedding Jetty, but more commonly are configured from a context XML file or WEB-INF/jetty-web.xml file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">maxFormContentSize</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>200000<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">maxFormKeys</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>200<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_configuring-form-limits-for-the-server"><a class="anchor" href="#_configuring-form-limits-for-the-server"></a><a class="link" href="#_configuring-form-limits-for-the-server">Configuring Form Limits for the Server</a></h4>
<div class="paragraph">
<p>If a context does not have specific form limits configured, then the server attributes are inspected to see if a server wide limit has been set on the size or keys.
The following XML shows how these attributes can be set in <code>jetty.xml</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setAttribute</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>org.eclipse.jetty.server.Request.maxFormContentSize<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>100000<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setAttribute</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>org.eclipse.jetty.server.Request.maxFormKeys<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>2000<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/configure&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="serving-aliased-files"><a class="anchor" href="#serving-aliased-files"></a><a class="link" href="#serving-aliased-files">Aliased Files and Symbolic links</a></h3>
<div class="paragraph">
<p>Web applications will often serve static content from the file system provided by the operating system running underneath the JVM.
However, because file systems often implement multiple aliased names for the same file, then security constraints and other servlet URI space mappings may inadvertently be bypassed by aliases.</p>
</div>
<div class="paragraph">
<p>A key example of this is case insensitivity and 8.3 filenames implemented by the Windows file system.
If a file within a web application called <code>/mysecretfile.txt</code> is protected by a security constraint on the URI <code>/mysecretfile.txt</code>, then a request to <code>/MySecretFile.TXT</code> will not match the URI constraint because URIs are case sensitive, but the Windows file system will report that a file does exist at that name and it will be served despite the security constraint.
Less well known than case insensitivity is that Windows files systems also support <a href="http://en.wikipedia.org/wiki/8.3_filename">8.3 filenames</a> for compatibility with legacy programs.
Thus a request to a URI like <code>/MYSECR~1.TXT</code> will again not match the security constraint, but will be reported as an existing file by the file system and served.</p>
</div>
<div class="paragraph">
<p>There are many examples of aliases, not just on Windows:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>NTFS Alternate stream names like <code>c:\test\file.txt::$DATA:name</code></p>
</li>
<li>
<p>OpenVMS support file versionig so that <code>/mysecret.txt;N</code> refers to version N of <code>/mysecret.txt</code> and is essentially an alias.</p>
</li>
<li>
<p>The clearcase software configuration management system provides a file system where <code>@@</code> in a file name is an alias to a specific version.</p>
</li>
<li>
<p>The Unix files system supports <code>/./foo.txt</code> as and alias for <code>/foo.txt</code></p>
</li>
<li>
<p>Many JVM implementations incorrectly assume the null character is a string terminator, so that a file name resulting from <code>/foobar.txt%00</code> is an alias for <code>/foobar.txt</code></p>
</li>
<li>
<p>Unix symbolic links and hard links are a form of aliases that allow the same file or directory to have multiple names.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>In addition, it is not just URI security constraints that can be bypassed. For example the mapping of the URI pattern <code>*.jsp</code> to the JSP
Servlet may be bypassed by an a request to an alias like <code>/foobar.jsp%00</code>, thus rather than execute the JSP, the source code of the JSP is returned by the file system.</p>
</div>
<div class="sect3">
<h4 id="_good-security-practise"><a class="anchor" href="#_good-security-practise"></a><a class="link" href="#_good-security-practise">Good Security Practise</a></h4>
<div class="paragraph">
<p>Part of the problem with aliases is that the standard web application security model is to allow all requests except the ones that are specifically denied by security constraints.
A best practice for security is to deny all requests and to permit only those that are specifically identified as allowable.
While it is possible to design web application security constraints in this style, it can be difficult in all circumstances and it is not the default. T
hus it is important for Jetty to be able to detect and deny requests to aliased static content.</p>
</div>
</div>
<div class="sect3">
<h4 id="file-alias-detection"><a class="anchor" href="#file-alias-detection"></a><a class="link" href="#file-alias-detection">Alias detection</a></h4>
<div class="paragraph">
<p>It is impossible for Jetty to know of all the aliases that may be implemented by the file system running beneath it, thus it does not attempt to make any specific checks for any know aliases.
Instead Jetty detects aliases by using the canonical path of a file.
If a file resource handled by jetty has a canonical name that differs from the name used to request the resource, then Jetty determines that the resource is an aliased request and it will not be returned by the <code>ServletContext.getResource(String)</code> method (or similar) and thus will not be served as static content nor used as the basis of a JSP.</p>
</div>
<div class="paragraph">
<p>This if Jetty is running on a Windows operating system, then a file called <code>/MySecret.TXT</code> will have a canonical name that exactly matches that case.
So while a request to <code>/mysecret.txt</code> or <code>/MYSECR~1.TXT</code> will result in a File Resource that matches the file, the different canonical name will indicate that those requests are aliases and they will not be served as static content and instead a 404 response returned.</p>
</div>
<div class="paragraph">
<p>Unfortunately this approach denies all aliases, including symbolic links, which can be useful in assembling complex web applications.</p>
</div>
</div>
<div class="sect3">
<h4 id="file-alias-serving"><a class="anchor" href="#file-alias-serving"></a><a class="link" href="#file-alias-serving">Serving Aliases and Symbolic Links</a></h4>
<div class="paragraph">
<p>Not all aliases are bad nor should be seen as attempts to subvert security constraints.
Specifically, symbolic links can be very useful when assembling complex web applications.
As such, Jetty contexts support an extensible <code>AliasCheck</code> mechanism to allow aliases resources to be inspected and conditionally served.
In this way, "good" aliases can be detected and served.
Jetty provides several utility implementations of the <code>AliasCheck</code> interface as nested classes with <code>ContextHandler</code>:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">ApproveAliases</dt>
<dd>
<p>Approve all aliases (<strong>Use with caution!</strong>).</p>
</dd>
<dt class="hdlist1">AllowSymLinkAliasChecker</dt>
<dd>
<p>Approve Aliases using the java-7 <code>Files.readSymbolicLink(path)</code> and <code>Path.toRealPath(&#8230;&#8203;)</code> APIs to check that aliases are valid symbolic links.</p>
</dd>
</dl>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
By default, Jetty serves aliased files for implementations running on UNIX as Contexts are created with both the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/AllowSymLinkAliasChecker.html"><code>AllowSymLinkAliasChecker</code></a> and <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/handler/ContextHandler.ApproveNonExistentDirectoryAliases.html"><code>ApproveNonExistentDirectoryAliases</code></a> alias checkers.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>An application is free to implement its own Alias checking.
Alias Checkers can be installed in a context via the following XML used in a context deployer file or <code>WEB-INF/jetty-web.xml</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="comment">&lt;!-- Allow symbolic links --&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addAliasCheck</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="configuring-security-secure-passwords"><a class="anchor" href="#configuring-security-secure-passwords"></a><a class="link" href="#configuring-security-secure-passwords">Secure Password Obfuscation</a></h3>
<div class="paragraph">
<p>There are many places where you might want to use and store a password, for example for the SSL connectors and user passwords in realms.</p>
</div>
<div class="paragraph">
<p>Passwords can be stored in clear text, obfuscated, checksummed or encrypted in order of increasing security.
The choice of method to secure a password depends on where you are using the password.
In some cases, such as keystore passwords and <code>DIGEST</code> authentication, the system must retrieve the original password, which requires the obfuscation method.
The drawback of the obfuscation algorithm is that it protects passwords <strong>from casual viewing only.</strong></p>
</div>
<div class="paragraph">
<p>When the stored password is compared to one a user enters, the handling code can apply the same algorithm that secures the stored password to the user input and compare results, making password authentication more secure.</p>
</div>
<div class="paragraph">
<p>The class <code>org.eclipse.jetty.util.security.Password</code> can be used to generate all varieties of passwords.</p>
</div>
<div class="paragraph">
<p>Run it without arguments to see usage instructions:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ java -cp lib/jetty-util-10.0.10.jar org.eclipse.jetty.util.security.Password
Usage - java org.eclipse.jetty.util.security.Password [&lt;user&gt;] &lt;password&gt;
If the password is ?, the user will be prompted for the password</code></pre>
</div>
</div>
<div class="paragraph">
<p>For example, to generate a secured version of the password <code>password</code> for the user <code>username</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ java -cp ../lib/jetty-util-10.0.10.jar org.eclipse.jetty.util.security.Password username password
2017-12-13 11:19:27.928:INFO::main: Logging initialized @95ms to org.eclipse.jetty.util.log.StdErrLog
password
OBF:1v2j1uum1xtv1zej1zer1xtn1uvk1v1v
MD5:5f4dcc3b5aa765d61d8327deb882cf99
CRYPT:usjRS48E8ZADM</code></pre>
</div>
</div>
<div class="paragraph">
<p>If using a external tool to create/verify the MD5 hash (such as <code>md5sum</code> or <code>md5</code>), be sure to verify a carriage return (CR) or new line is not added.
For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">//With a CR included
$ echo password | md5sum
286755fad04869ca523320acce0dc6a4 *-
//Using the `-n` option to exclude a new line from being added.
$ echo -n password | md5sum
5f4dcc3b5aa765d61d8327deb882cf99 *-</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
When using the <code>DIGEST</code> method in tandem with an MD5 hash, you must hash the entire <code>user:realm:password</code> string or you will encounter issues with authenticating.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ java -cp ../lib/jetty-util-10.0.10.jar org.eclipse.jetty.util.security.Password username username:realm:password
2017-12-13 11:34:33.263:INFO::main: Logging initialized @97ms to org.eclipse.jetty.util.log.StdErrLog
username:realm:password
OBF:1w281yf41v1x1z7e1xmi1v1p1tvv1v901c3j1x8k1ugo1ri71uh21x8a1c3j1v9m1tv71v2p1xms1z7o1v2h1yf21w1a
MD5:66999343281b2624585fd58cc9d36dfc
CRYPT:usulxZfApLefk
$ echo -n username:realm:password | md5sum
66999343281b2624585fd58cc9d36dfc *-</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can now cut and paste whichever secure version you choose into your configuration file or Java code.</p>
</div>
<div class="paragraph">
<p>For example, the last line below shows how you would implement the encrypted password generated above into the properties file for a <code>LoginService</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="bash">admin: CRYPT:ad1ks..kc.1Ug,server-administrator,content-administrator,admin
other: OBF:1xmk1w261u9r1w1c1xmq
guest: guest,read-only
me:CRYPT:me/ks90E221EY</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
Don&#8217;t forget to also copy the OBF:, MD5: or CRYPT: prefix on the generated password. It will not be usable by Jetty without it.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>You can also use obfuscated passwords in Jetty xml files where a plain text password is required.
Here&#8217;s an example setting the password for a JDBC Datasource with obfuscation:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">DSTest</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.plus.jndi.Resource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>jdbc/DSTest<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">com.jolbox.bonecp.BoneCPDataSource</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">driverClass</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>com.mysql.jdbc.Driver<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">jdbcUrl</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>jdbc:mysql://localhost:3306/foo<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">username</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>dbuser<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">password</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.util.security.Password</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">deobfuscate</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>OBF:1ri71v1r1v2n1ri71shq1ri71shs1ri71v1r1v2n1ri7<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">minConnectionsPerPartition</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>5<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">maxConnectionsPerPartition</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>50<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">acquireIncrement</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>5<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">idleConnectionTestPeriod</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>30<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="setting-port80-access"><a class="anchor" href="#setting-port80-access"></a><a class="link" href="#setting-port80-access">Setting Port 80 Access for a Non-Root User</a></h3>
<div class="paragraph">
<p>On Unix-based systems, port 80 is protected; typically only the superuser <code>root</code> can open it. For security reasons, it is not desirable to run the server as <code>root</code>.
This page presents several options to access port 80 as a non-root user, including using <code>ipchains</code>, <code>iptables</code>, Jetty&#8217;s SetUID feature, <code>xinetd</code>, and the Solaris 10 User Rights Management Framework.</p>
</div>
<div class="sect3">
<h4 id="using-ipchains"><a class="anchor" href="#using-ipchains"></a><a class="link" href="#using-ipchains">Using ipchains</a></h4>
<div class="paragraph">
<p>On some Linux systems you can use the <em>ipchains REDIRECT</em> mechanism to redirect from one port to another inside the kernel (if <code>ipchains</code> is not available, then <code>iptables</code> usually is):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># /sbin/ipchains -I input --proto TCP --dport 80 -j REDIRECT 8080</code></pre>
</div>
</div>
<div class="paragraph">
<p>This command instructs the system as follows: "Insert into the kernel&#8217;s packet filtering the following as the first rule to check on incoming packets: if the protocol is TCP and the destination port is 80, redirect the packet to port 8080".
Be aware that your kernel must be compiled with support for <code>ipchains</code> (virtually all stock kernels are).
You must also have the <code>ipchains</code> command-line utility installed.
You can run this command at any time, preferably just once, since it inserts another copy of the rule every time you run it.</p>
</div>
</div>
<div class="sect3">
<h4 id="using-iptables"><a class="anchor" href="#using-iptables"></a><a class="link" href="#using-iptables">Using iptables</a></h4>
<div class="paragraph">
<p>On many Linux systems you can use the <code>iptables</code> REDIRECT mechanism to redirect from one port to another inside the kernel (if <code>iptables</code> is not available, then usually <code>ipchains</code> is).</p>
</div>
<div class="paragraph">
<p>You need to add something like the following to the startup scripts or your firewall rules:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># /sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080</code></pre>
</div>
</div>
<div class="paragraph">
<p>The underlying model of <code>iptables</code> is different from <code>ipchains</code>, so the forwarding normally happens only to packets originating outside of the server itself.
You also need to allow incoming packets to port 8080 if you use <code>iptables</code> as a local firewall.</p>
</div>
<div class="paragraph">
<p>Be careful to place rules like this one early in your <em>input</em> chain.
Such rules must precede any rule that accepts the packet, otherwise the redirection won&#8217;t occur.
You can insert as many rules as required if your server needs to listen on multiple ports, as for HTTPS.</p>
</div>
</div>
<div class="sect3">
<h4 id="configuring-jetty-setuid-feature"><a class="anchor" href="#configuring-jetty-setuid-feature"></a><a class="link" href="#configuring-jetty-setuid-feature">Configuring Jetty&#8217;s SetUID Feature</a></h4>
<div class="paragraph">
<p><a href="http://en.wikipedia.org/wiki/Setuid">SetUID</a> is a technique that uses Unix-like file system access rights to allow users to run an executable that would otherwise require higher privileges.</p>
</div>
<div class="paragraph">
<p>Jetty&#8217;s <code>SetUID</code> module allows you to run Jetty as a normal user even when you need to run Jetty on port 80 or 443.</p>
</div>
<div class="paragraph">
<p>To use it with the Jetty distribution:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Ensure that you have the <code>http.mod</code> (and <a href="#quickstart-starting-https">https.mod</a> if you are using SSL) <a href="#startup-modules">modules enabled</a> for the <a href="#creating-jetty-base">base</a> you are using.
The <code>http.mod</code> is enabled by default in the distribution, while the <a href="#quickstart-starting-https">https.mod</a> is only enabled in the <a href="#demo-webapps-base">demo-base</a> directory.</p>
</li>
<li>
<p>Ensure that you have <a href="#quickstart-changing-jetty-port">changed the http port</a> to 80 (and <a href="#quickstart-changing-https-port">changed the https port</a> to 443 if you are using SSL).</p>
</li>
<li>
<p>Enable the <code>setuid.mod</code> module:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># java -jar start.jar --add-to-start=setuid</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The --add-to-start command will enable the setuid module for this and all subsequent executions of jetty.
There are other ways to enable the module, such as for a single execution.
For more information on the alternatives see the section on <a href="#startup-modules">Managing Startup Modules</a>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</li>
<li>
<p>Edit the configuration for the <code>setuid</code> module to substitute the <code>userid</code> and <code>groupid</code> of the user to switch to after starting.
If your server instance has a <code>${jetty.base/start.d}</code> directory, this configuration is in the <code>start.d/setuid.ini</code> file instead.
Otherwise. this configuration is in the <code>${jetty.base}start.ini</code> file.</p>
<div class="literalblock">
<div class="content">
<pre>Below are the lines to configure:</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">jetty.startServerAsPrivileged=false
jetty.username=foo
jetty.groupname=bar
jetty.umask=002</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
As well as opening the connectors as <code>root</code>, you can also have Jetty start the Server as <code>root</code> before changing to the non-<code>root</code> user.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</li>
<li>
<p>A native code library is required to perform user switching.
This code is hosted as part of the <a href="https://github.com/eclipse/jetty.toolchain">Jetty ToolChain</a> project and is released independently from Jetty itself.
You can find the source code in the <a href="https://github.com/eclipse/jetty.toolchain/tree/master/jetty-setuid">eclipse/jetty.toolchain/jetty-setuid</a> project.
Build it locally, which will produce a native library appropriate for the operating system:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># mvn clean install</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you built on a linux machine you will find the native library in <code>jetty-setuid/libsetuid-linux/target/libsetuid-linux.so</code>.
If you built on a different operating system you will find the library in a different subdirectory, with the name containing the name of the operating system.
You may want copy this file into your Jetty distribution&#8217;s lib directory.</p>
</div>
</li>
<li>
<p>Start Jetty as the <code>root</code> user in your base directory, providing the location of the native library to Java.
Below is an example of how to do it from the command line, assuming you are in the <a href="#demo-webapps-base">demo-base</a> directory:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># sudo java -Djava.library.path=libsetuid-linux -jar $JETTY_HOME/start.jar</code></pre>
</div>
</div>
</li>
</ol>
</div>
</div>
<div class="sect3">
<h4 id="using-solaris10-user-rights-management-framework"><a class="anchor" href="#using-solaris10-user-rights-management-framework"></a><a class="link" href="#using-solaris10-user-rights-management-framework">Using the Solaris 10 User Rights Management Framework</a></h4>
<div class="paragraph">
<p>Solaris 10 provides a User Rights Management framework that can permit users and processes superuser-like abilities:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">usermod -K defaultpriv=basic,net_privaddr myself</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now the <code>myself</code> user can bind to port 80.</p>
</div>
<div class="paragraph">
<p>Refer to the <a href="http://docs.oracle.com/cd/E23823_01/html/816-4557/prbactm-1.html#scrolltoc">Solaris 10</a> and <a href="http://docs.oracle.com/cd/E23824_01/html/821-1456/prbactm-1.html#scrolltoc">Solaris 11 Security Services documentation</a> for more information.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="jaas-support"><a class="anchor" href="#jaas-support"></a><a class="link" href="#jaas-support">JAAS Support</a></h3>
<div class="paragraph">
<p>JAAS implements a Java version of the standard Pluggable Authentication Module (PAM) framework.</p>
</div>
<div class="paragraph">
<p>JAAS can be used for two purposes:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>for authentication of users, to reliably and securely determine who is currently executing Java code, regardless of whether the code is running as an application, an applet, a bean, or a servlet</p>
</li>
<li>
<p>for authorization of users to ensure they have the access control rights (permissions) required to do the actions performed</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>JAAS authentication is performed in a pluggable fashion.
This permits applications to remain independent from underlying authentication technologies.
New or updated authentication technologies can be plugged under an application without requiring modifications to the application itself.
Applications enable the authentication process by instantiating a <code>LoginContext</code> object, which in turn references a configuration to determine the authentication technology(ies), or <code>LoginModule</code>(s), to be used in performing the authentication.
Typical <code>LoginModules</code> may prompt for and verify a username and password.
Others may read and verify a voice or fingerprint sample.</p>
</div>
<div class="paragraph">
<p>See Java Authentication and Authorization Service (JAAS) <a href="http://java.sun.com/javase/6/docs/technotes/guides/security/jaas/JAASRefGuide.html">Reference Guide</a> for more information about JAAS.</p>
</div>
<div class="sect3">
<h4 id="jetty-jaas"><a class="anchor" href="#jetty-jaas"></a><a class="link" href="#jetty-jaas">Jetty and JAAS</a></h4>
<div class="paragraph">
<p>Many application servers support JAAS as a means of bringing greater flexibility to the declarative security models of the J2EE (now known as the JavaEE) <a href="http://java.sun.com/javaee/index.jsp">specification</a>.
Jetty support for JAAS provides greater alternatives for servlet security, and increases the portability of web applications.</p>
</div>
<div class="paragraph">
<p>The JAAS support aims to dictate as little as possible whilst providing a sufficiently flexible infrastructure to allow users to drop in their
own custom <a href="http://java.sun.com/j2se/1.4.2/docs/guide/security/jaas/JAASLMDevGuide.html">LoginModules</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="jaas-configuration"><a class="anchor" href="#jaas-configuration"></a><a class="link" href="#jaas-configuration">Configuration</a></h4>
<div class="paragraph">
<p>Using JAAS with Jetty is very simply a matter of declaring a <code>org.eclipse.jetty.jaas.JAASLoginService</code>, creating a JAAS login module configuration file and specifying it on the Jetty run line.
Let&#8217;s look at an example.</p>
</div>
<div class="sect4">
<h5 id="_step-1"><a class="anchor" href="#_step-1"></a><a class="link" href="#_step-1">Step 1</a></h5>
<div class="paragraph">
<p>Configure a Jetty <code>org.eclipse.jetty.jaas.JAASLoginService</code> to match the <code>&lt;realm-name&gt;</code> in your <code>web.xml</code> file. For example, if the <code>web.xml</code> contains a realm called "Test JAAS Realm" like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;login-config&gt;</span>
<span class="tag">&lt;auth-method&gt;</span>FORM<span class="tag">&lt;/auth-method&gt;</span>
<span class="tag">&lt;realm-name&gt;</span>Test JAAS Realm<span class="tag">&lt;/realm-name&gt;</span>
<span class="tag">&lt;form-login-config&gt;</span>
<span class="tag">&lt;form-login-page&gt;</span>/login/login<span class="tag">&lt;/form-login-page&gt;</span>
<span class="tag">&lt;form-error-page&gt;</span>/login/error<span class="tag">&lt;/form-error-page&gt;</span>
<span class="tag">&lt;/form-login-config&gt;</span>
<span class="tag">&lt;/login-config&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>then you need to create a <code>JAASLoginService</code> with the matching realm name of "Test JAAS Realm":</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.jaas.JAASLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test JAAS Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">LoginModuleName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>xyz<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>LoginModuleName</code> must match the name of your LoginModule as declared in your login module configuration file (see <a href="#jaas-step-2">Step 2</a>).</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<i class="fa icon-caution" title="Caution"></i>
</td>
<td class="content">
The name of the realm-name that you declare in <code>web.xml</code> must match <strong>exactly</strong> the <code>Name</code> field of your <code>JAASLoginService</code>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>You can declare your <code>JAASLoginService</code> in a couple of different ways:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>If you have more than one webapp that you would like to use the same security infrastructure, then you can declare your <code>JAASLoginService</code> in a top-level Jetty xml file as a bean that is added to the <code>org.eclipse.jetty.server.Server</code>.
An example:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addBean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.jaas.JAASLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test JAAS Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">LoginModuleName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>xyz<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</li>
<li>
<p>Alternatively, you can use a <code>JAASLoginService</code> with just a specific webapp by creating a <a href="#deployable-descriptor-file">context xml</a> file for the webapp, and specifying the <code>JAASLoginService</code> in it:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">securityHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.ConstraintSecurityHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">loginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.jaas.JAASLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test JAAS Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">loginModuleName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>xyz<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</li>
</ol>
</div>
</div>
<div class="sect4">
<h5 id="jaas-step-2"><a class="anchor" href="#jaas-step-2"></a><a class="link" href="#jaas-step-2">Step 2</a></h5>
<div class="paragraph">
<p>Set up your <code>LoginModule</code> in a configuration file, following the <a href="https://docs.oracle.com/javase/7/docs/api/javax/security/auth/login/Configuration.html">syntax rules</a> :</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="ini">xyz {
com.acme.SomeLoginModule required debug=true;
};</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<i class="fa icon-caution" title="Caution"></i>
</td>
<td class="content">
It is imperative that the application name on the first line is <strong>exactly</strong> the same as the <code>LoginModuleName</code> of your <code>JAASLoginService</code>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>You may find it convenient to name this configuration file as <code>etc/login.conf</code> because, as we will see below, some of the wiring up for JAAS has been done for you.</p>
</div>
</div>
<div class="sect4">
<h5 id="_step-3"><a class="anchor" href="#_step-3"></a><a class="link" href="#_step-3">Step 3</a></h5>
<div class="paragraph">
<p>You now need to invoke Jetty with support for JAAS.
There are 2 aspects to this:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>adding JAAS-related jars to the Jetty container classpath</p>
</li>
<li>
<p>setting the System property <code>java.security.auth.login.config</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>To accomplish the above, use the Jetty <a href="#startup-overview">startup</a> <a href="#startup-modules">modules mechanism</a> to add the JAAS <a href="#startup-modules">module</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">java -jar start.jar --add-to-start=jaas</code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The top level of the distribution does not have the JAAS module enabled by default.
However, there are several <a href="#demo-webapps-base">demo webapps</a> - including a JAAS webapp - available in the <code>demo-base</code> directory of the distribution which has pre-enabled the JAAS module.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>Now you will have a file named <code>start.d/jaas.ini</code>, which contains:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="ini">--module=jaas
jaas.login.conf=etc/login.conf</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>jaas.login.conf</code> property refers to the location of your <code>LoginModule</code> configuration file that you established in <a href="#jaas-step-2">Step 2</a>.
If you called it <code>etc/login.conf</code>, then your work is done. Otherwise, change the value of the <code>jaas.login.conf</code> property to be the location of your LoginModule configuration file.
Jetty will automatically use this property to set the value of the System property <code>java.security.auth.login.config.</code></p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_a-closer-look-at-jaasloginservice"><a class="anchor" href="#_a-closer-look-at-jaasloginservice"></a><a class="link" href="#_a-closer-look-at-jaasloginservice">A Closer Look at JAASLoginService</a></h4>
<div class="paragraph">
<p>To allow the greatest degree of flexibility in using JAAS with web applications, the <code>JAASLoginService</code> supports a couple of configuration options.
Note that you don&#8217;t ordinarily need to set these explicitly, as Jetty has defaults which will work in 99% of cases.
However, should you need to, you can configure:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>a CallbackHandler (Default: <code>org.eclipse.jetty.jaas.callback.DefaultCallbackHandler</code>)</p>
</li>
<li>
<p>a list of classnames for the Principal implementation that equate to a user role (Default: <code>org.eclipse.jetty.jaas.JAASRole</code>)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of setting each of these (to their default values):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.jaas.JAASLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Name</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>Test JAAS Realm<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">LoginModuleName</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>xyz<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">CallbackHandlerClass</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
org.eclipse.jetty.jaas.callback.DefaultCallbackHandler
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">roleClassNames</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Array</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">java.lang.String</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Item&gt;</span>org.eclipse.jetty.jaas.JAASRole<span class="tag">&lt;/Item&gt;</span>
<span class="tag">&lt;/Array&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="sect4">
<h5 id="_callbackhandler"><a class="anchor" href="#_callbackhandler"></a><a class="link" href="#_callbackhandler">CallbackHandler</a></h5>
<div class="paragraph">
<p>A CallbackHandler is responsible for interfacing with the user to obtain usernames and credentials to be authenticated.</p>
</div>
<div class="paragraph">
<p>Jetty ships with the <code>org.eclipse.jetty.jaas.DefaultCallbackHandler</code> which interfaces the information contained in the request to the Callbacks that are requested by <code>LoginModules</code>.
You can replace this default with your own implementation if you have specific requirements not covered by the default.</p>
</div>
</div>
<div class="sect4">
<h5 id="_role-principal-implementation-class"><a class="anchor" href="#_role-principal-implementation-class"></a><a class="link" href="#_role-principal-implementation-class">Role Principal Implementation Class</a></h5>
<div class="paragraph">
<p>When <code>LoginModules</code> authenticate a user, they usually also gather all of the roles that a user has and place them inside the JAAS Subject.
As <code>LoginModules</code> are free to use their own implementation of the JAAS Principal to put into the Subject, Jetty needs to know which Principals represent the user and which represent his/her roles when performing authorization checks on <code>&lt;security-constraint&gt;</code>. The example <code>LoginModules</code> that ship with Jetty all use the <code>org.eclipse.jetty.jaas.JAASRole</code> class. However, if you have plugged in other <code>LoginModules</code>, you must configure the classnames of their role Principal implementations.</p>
</div>
</div>
<div class="sect4">
<h5 id="_sample-loginmodules"><a class="anchor" href="#_sample-loginmodules"></a><a class="link" href="#_sample-loginmodules">Sample LoginModules</a></h5>
<div class="ulist">
<ul>
<li>
<p><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/jaas/spi/JDBCLoginModule.html"><code>org.eclipse.jetty.jaas.spi.JDBCLoginModule</code></a></p>
</li>
<li>
<p><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/jaas/spi/PropertyFileLoginModule.html"><code>org.eclipse.jetty.jaas.spi.PropertyFileLoginModule</code></a></p>
</li>
<li>
<p><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/jaas/spi/DataSourceLoginModule.html"><code>org.eclipse.jetty.jaas.spi.DataSourceLoginModule</code></a></p>
</li>
<li>
<p><a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/jaas/spi/LdapLoginModule.html"><code>org.eclipse.jetty.jaas.ldap.LdapLoginModule</code></a></p>
</li>
</ul>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Passwords can be stored in clear text, obfuscated or checksummed.
The class <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/util/security/Password.html"><code>org.eclipse.jetty.util.security.Password</code></a> should be used to generate all varieties of passwords,the output from which can be put in to property files or entered into database tables.
See more on this under the Configuration section on <a href="#configuring-security-secure-passwords">securing passwords</a>.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect4">
<h5 id="_jdbcloginmodule"><a class="anchor" href="#_jdbcloginmodule"></a><a class="link" href="#_jdbcloginmodule">JDBCLoginModule</a></h5>
<div class="paragraph">
<p>The <code>JDBCLoginModule</code> stores user passwords and roles in a database that are accessed via JDBC calls.
You can configure the JDBC connection information, as well as the names of the table and columns storing the username and credential, and the names of the table and columns storing the roles.</p>
</div>
<div class="paragraph">
<p>Here is an example login module configuration file entry for it using an HSQLDB driver:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="ini">jdbc {
org.eclipse.jetty.jaas.spi.JDBCLoginModule required
debug=&quot;true&quot;
dbUrl=&quot;jdbc:hsqldb:.&quot;
dbUserName=&quot;sa&quot;
dbDriver=&quot;org.hsqldb.jdbcDriver&quot;
userTable=&quot;myusers&quot;
userField=&quot;myuser&quot;
credentialField=&quot;mypassword&quot;
userRoleTable=&quot;myuserroles&quot;
userRoleUserField=&quot;myuser&quot;
userRoleRoleField=&quot;myrole&quot;;
};</code></pre>
</div>
</div>
<div class="paragraph">
<p>There is no particular schema required for the database tables storing the authentication and role information.
The properties <code>userTable</code>, <code>userField</code>, <code>credentialField</code>, <code>userRoleTable</code>, <code>userRoleUserField</code>, <code>userRoleRoleField</code> configure the names of the tables and the columns within them that are used to format the following queries:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"> <span class="class">select</span> &lt;credentialField&gt; <span class="keyword">from</span> &lt;userTable&gt;
<span class="keyword">where</span> &lt;userField&gt; =<span class="error">?</span>
<span class="class">select</span> &lt;userRoleRoleField&gt; <span class="keyword">from</span> &lt;userRoleTable&gt;
<span class="keyword">where</span> &lt;userRoleUserField&gt; =<span class="error">?</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Credential and role information is lazily read from the database when a previously unauthenticated user requests authentication.
Note that this information is <em>only</em> cached for the length of the authenticated session.
When the user logs out or the session expires, the information is flushed from memory.</p>
</div>
<div class="paragraph">
<p>Note that passwords can be stored in the database in plain text or encoded formats - see the note on "Passwords/Credentials" above.</p>
</div>
</div>
<div class="sect4">
<h5 id="_datasourceloginmodule"><a class="anchor" href="#_datasourceloginmodule"></a><a class="link" href="#_datasourceloginmodule">DataSourceLoginModule</a></h5>
<div class="paragraph">
<p>Similar to the <code>JDBCLoginModule</code>, but this <code>LoginModule</code> uses a <code>DataSource</code> to connect to the database instead of a JDBC driver. The <code>DataSource</code> is obtained by performing a JNDI lookup on <code>java:comp/env/${dnJNDIName}</code>.</p>
</div>
<div class="paragraph">
<p>A sample login module configuration using this method:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="ini">ds {
org.eclipse.jetty.jaas.spi.DataSourceLoginModule required
debug=&quot;true&quot;
dbJNDIName=&quot;ds&quot;
userTable=&quot;myusers&quot;
userField=&quot;myuser&quot;
credentialField=&quot;mypassword&quot;
userRoleTable=&quot;myuserroles&quot;
userRoleUserField=&quot;myuser&quot;
userRoleRoleField=&quot;myrole&quot;;
};</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_propertyfileloginmodule"><a class="anchor" href="#_propertyfileloginmodule"></a><a class="link" href="#_propertyfileloginmodule">PropertyFileLoginModule</a></h5>
<div class="paragraph">
<p>With this login module implementation, the authentication and role information is read from a property file.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="ini">props {
org.eclipse.jetty.jaas.spi.PropertyFileLoginModule required
debug=&quot;true&quot;
file=&quot;/somewhere/somefile.props&quot;;
};</code></pre>
</div>
</div>
<div class="paragraph">
<p>The file parameter is the location of a properties file of the same format as the <code>etc/realm.properties</code> example file.
The format is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">&lt;username&gt;: &lt;password&gt;[,&lt;rolename&gt; ...]</code></pre>
</div>
</div>
<div class="paragraph">
<p>Here&#8217;s an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="ini">fred: OBF:1xmk1w261u9r1w1c1xmq,user,admin
harry: changeme,user,developer
tom: MD5:164c88b302622e17050af52c89945d44,user
dick: CRYPT:adpexzg3FUZAk,admin</code></pre>
</div>
</div>
<div class="paragraph">
<p>The contents of the file are fully read in and cached in memory the first time a user requests authentication.</p>
</div>
</div>
<div class="sect4">
<h5 id="_ldaploginmodule"><a class="anchor" href="#_ldaploginmodule"></a><a class="link" href="#_ldaploginmodule">LdapLoginModule</a></h5>
<div class="paragraph">
<p>Here&#8217;s an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="ini">ldaploginmodule {
org.eclipse.jetty.jaas.spi.LdapLoginModule required
debug=&quot;true&quot;
contextFactory=&quot;com.sun.jndi.ldap.LdapCtxFactory&quot;
hostname=&quot;ldap.example.com&quot;
port=&quot;389&quot;
bindDn=&quot;cn=Directory Manager&quot;
bindPassword=&quot;directory&quot;
authenticationMethod=&quot;simple&quot;
forceBindingLogin=&quot;false&quot;
userBaseDn=&quot;ou=people,dc=alcatel&quot;
userRdnAttribute=&quot;uid&quot;
userIdAttribute=&quot;uid&quot;
userPasswordAttribute=&quot;userPassword&quot;
userObjectClass=&quot;inetOrgPerson&quot;
roleBaseDn=&quot;ou=groups,dc=example,dc=com&quot;
roleNameAttribute=&quot;cn&quot;
roleMemberAttribute=&quot;uniqueMember&quot;
roleObjectClass=&quot;groupOfUniqueNames&quot;;
};</code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_writing-your-own-loginmodule"><a class="anchor" href="#_writing-your-own-loginmodule"></a><a class="link" href="#_writing-your-own-loginmodule">Writing your Own LoginModule</a></h4>
<div class="paragraph">
<p>If you want to implement your own custom <code>LoginModule</code>, there are two classes to be familiar with: <code>org.eclipse.jetty.jaas.spi.AbstractLoginModule</code> and <code>org.eclipse.jetty.jaas.spi.UserInfo</code>.</p>
</div>
<div class="paragraph">
<p>The <code>org.eclipse.jetty.jaas.spi.AbstractLoginModule</code> implements all of the <code>javax.security.auth.spi.LoginModule</code> methods.
All you need to do is to implement the <code>getUserInfo</code> method to return a <code>org.eclipse.jetty.jaas.UserInfo</code> instance which encapsulates the username, password and role names (note: as <code>java.lang.Strings</code>) for a user.</p>
</div>
<div class="paragraph">
<p>The <code>AbstractLoginModule</code> does not support any caching, so if you want to cache UserInfo (eg as does the <code>org.eclipse.jetty.jaas.spi.PropertyFileLoginModule</code>) then you must provide this yourself.</p>
</div>
</div>
<div class="sect3">
<h4 id="_other-goodies"><a class="anchor" href="#_other-goodies"></a><a class="link" href="#_other-goodies">Other Goodies</a></h4>
<div class="sect4">
<h5 id="_servletrequestcallback"><a class="anchor" href="#_servletrequestcallback"></a><a class="link" href="#_servletrequestcallback">ServletRequestCallback</a></h5>
<div class="paragraph">
<p>This callback gives you access to the ServletRequest that is involved in the authentication, and thus to other features like the current Session. This callback can be configured in your custom LoginModule implementation. Note that none of the LoginModule implementations provided with Jetty currently use this callback.</p>
</div>
</div>
<div class="sect4">
<h5 id="_requestparametercallback"><a class="anchor" href="#_requestparametercallback"></a><a class="link" href="#_requestparametercallback">RequestParameterCallback</a></h5>
<div class="paragraph">
<p>As all servlet containers intercept and process a form submission with action <code>j_security_check</code>, it is usually not possible to insert any extra input fields onto a login form with which to perform authentication: you may only pass <code>j_username</code> and <code>j_password</code>.
For those rare occasions when this is not good enough, and you require more information from the user in order to authenticate them, you can use the JAAS callback handler <code>org.eclipse.jetty.jaas.callback.RequestParameterCallback</code>.
This callback gives you access to all parameters that were passed in the form submission.
To use it, in the <code>login()</code> method of your custom login module, add the <code>RequestParameterCallback</code> to the list of callback handlers the login module uses, tell it which params you are interested in, and then get the value of the parameter back.
Here is an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">class</span> <span class="class">FooLoginModule</span> <span class="directive">extends</span> AbstractLoginModule
{
<span class="directive">public</span> <span class="type">boolean</span> login()
<span class="directive">throws</span> <span class="exception">LoginException</span>
{
<span class="predefined-type">Callback</span><span class="type">[]</span> callbacks = <span class="keyword">new</span> <span class="predefined-type">Callback</span>[<span class="integer">3</span>];
callbacks[<span class="integer">0</span>] = <span class="keyword">new</span> <span class="predefined-type">NameCallback</span>();
callbacks[<span class="integer">1</span>] = <span class="keyword">new</span> ObjectCallback();
<span class="comment">//as an example, look for a param named &quot;extrainfo&quot; in the request</span>
<span class="comment">//use one RequestParameterCallback() instance for each param you want to access</span>
callbacks[<span class="integer">2</span>] = <span class="keyword">new</span> RequestParameterCallback ();
((RequestParameterCallback)callbacks[<span class="integer">2</span>]).setParameterName (<span class="string"><span class="delimiter">&quot;</span><span class="content">extrainfo</span><span class="delimiter">&quot;</span></span>);
callbackHandler.handle(callbacks);
<span class="predefined-type">String</span> userName = ((<span class="predefined-type">NameCallback</span>)callbacks[<span class="integer">0</span>]).getName();
<span class="predefined-type">Object</span> pwd = ((ObjectCallback)callbacks[<span class="integer">1</span>]).getObject();
<span class="predefined-type">List</span> paramValues = ((RequestParameterCallback)callbacks[<span class="integer">2</span>]).getParameterValues();
<span class="comment">//use the userName, pwd and the value(s) of the parameter named &quot;extrainfo&quot; to</span>
<span class="comment">//authenticate the user</span>
}
}</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_example-jaas-webapp"><a class="anchor" href="#_example-jaas-webapp"></a><a class="link" href="#_example-jaas-webapp">Example JAAS WebApp</a></h5>
<div class="paragraph">
<p>An example webapp using JAAS can be found in the Jetty GitHub repository:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/tests/test-webapps/test-jaas-webapp">https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/tests/test-webapps/test-jaas-webapp</a></p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="spnego-support"><a class="anchor" href="#spnego-support"></a><a class="link" href="#spnego-support">SPNEGO Support</a></h3>
<div class="paragraph">
<p>Simple and Protected GSSAPI Negotiation Mechanism (SPNEGO) is a way for users
to be seamlessly authenticated when running on systems that rely on Kerberos
for authentication, such as Windows Active Directory based networks.</p>
</div>
<div class="paragraph">
<p>Jetty supports this type of authentication and authorization through the JDK
(which has been enabled since the later versions of Java 6 and 7).</p>
</div>
<div class="sect3">
<h4 id="_configuring-jetty-and-spnego"><a class="anchor" href="#_configuring-jetty-and-spnego"></a><a class="link" href="#_configuring-jetty-and-spnego">Configuring Jetty and SPNEGO</a></h4>
<div class="paragraph">
<p>To run with SPNEGO enabled the following command line options are required:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">-Djava.security.krb5.conf=/path/to/krb5.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>For debugging the SPNEGO authentication the following options are helpful:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">-Dorg.eclipse.jetty.LEVEL=debug
-Dsun.security.spnego.debug=true
-Dsun.security.jgss.debug=true
-Dsun.security.krb5.debug=true</code></pre>
</div>
</div>
<div class="paragraph">
<p>SPNEGO authentication must be enabled in the webapp in the following way.
The name of the role will be different for your network.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;security-constraint&gt;</span>
<span class="tag">&lt;web-resource-collection&gt;</span>
<span class="tag">&lt;web-resource-name&gt;</span>Secure Area<span class="tag">&lt;/web-resource-name&gt;</span>
<span class="tag">&lt;url-pattern&gt;</span>/secure/me/*<span class="tag">&lt;/url-pattern&gt;</span>
<span class="tag">&lt;/web-resource-collection&gt;</span>
<span class="tag">&lt;auth-constraint&gt;</span>
<span class="comment">&lt;!-- this is the domain that the user is a member of --&gt;</span>
<span class="tag">&lt;role-name&gt;</span>MORTBAY.ORG<span class="tag">&lt;/role-name&gt;</span>
<span class="tag">&lt;/auth-constraint&gt;</span>
<span class="tag">&lt;/security-constraint&gt;</span>
<span class="tag">&lt;login-config&gt;</span>
<span class="tag">&lt;auth-method&gt;</span>SPNEGO<span class="tag">&lt;/auth-method&gt;</span>
<span class="tag">&lt;realm-name&gt;</span>Test Realm<span class="tag">&lt;/realm-name&gt;</span>
<span class="comment">&lt;!-- optionally to add custom error page --&gt;</span>
<span class="tag">&lt;spnego-login-config&gt;</span>
<span class="tag">&lt;spnego-error-page&gt;</span>/loginError.html?param=foo<span class="tag">&lt;/spnego-error-page&gt;</span>
<span class="tag">&lt;/spnego-login-config&gt;</span>
<span class="tag">&lt;/login-config&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>A corresponding <code>UserRealm</code> needs to be created either programmatically if
embedded, via the <code>jetty.xml</code> or in a context file for the webapp.</p>
</div>
<div class="paragraph">
<p>This is what the configuration within a context XML file would look like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Get</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">securityHandler</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">loginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.ConfigurableSpnegoLoginService</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>Test Realm<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">authorizationService</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">keyTabPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span><span class="tag">&lt;Ref</span> <span class="attribute-name">refid</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">keyTabPath</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span><span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/New&gt;</span>
<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;/Get&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>On the Windows Active Domain Controller run:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ setspn -A HTTP/linux.mortbay.org ADUser</code></pre>
</div>
</div>
<div class="paragraph">
<p>To create the keyTab file use the following process:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ ktpass -out c:\dir\krb5.keytab -princ HTTP/linux.mortbay.org@MORTBAY.ORG -mapUser ADUser -mapOp set -pass ADUserPWD -crypto RC4-HMAC-NT -pType KRB5_NT_PRINCIPAL</code></pre>
</div>
</div>
<div class="paragraph">
<p>This step will give you the keyTab file which should then be copied to the
machine running the http server and referenced from the configuration files.</p>
</div>
</div>
<div class="sect3">
<h4 id="_configuring-firefox"><a class="anchor" href="#_configuring-firefox"></a><a class="link" href="#_configuring-firefox">Configuring Firefox</a></h4>
<div class="paragraph">
<p>The follows steps have been required to inform Firefox that it should use a negotiation dialog to authenticate.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Browse to about:config and agree to the warnings</p>
</li>
<li>
<p>Search through to find the 'network' settings</p>
</li>
<li>
<p>Set <code>network.negotiate-auth.delegation-uris</code> to <a href="http://,https://" class="bare">http://,https://</a></p>
</li>
<li>
<p>Set <code>network.negotiate-auth.trusted-uris</code> to <a href="http://,https://" class="bare">http://,https://</a></p>
</li>
</ol>
</div>
</div>
<div class="sect3">
<h4 id="_configuring-internet-explorer"><a class="anchor" href="#_configuring-internet-explorer"></a><a class="link" href="#_configuring-internet-explorer">Configuring Internet Explorer</a></h4>
<div class="paragraph">
<p>The follows steps have been required to inform Internet Explorer that it should use a negotiation dialog to authenticate.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Tools &#8594; Options &#8594; Security &#8594; Local Intranet &#8594; Sites (everything should be checked here)</p>
</li>
<li>
<p>Tools &#8594; Options &#8594; Security &#8594; Local Intranet &#8594; Sites &#8594; Advanced (add url to server (<code>http://</code> and/or <code>https://</code>&#8201;&#8212;&#8201;use the hostname, not the IP)</p>
</li>
<li>
<p>Tools &#8594; Options &#8594; Security &#8594; Local Intranet &#8594; Sites &#8594; Advanced &#8594; Close</p>
</li>
<li>
<p>Tools &#8594; Options &#8594; Security &#8594; Local Intranet &#8594; Sites &#8594; Ok</p>
</li>
<li>
<p>Tools &#8594; Options &#8594; Advanced &#8594; Security (in the checkbox list)</p>
</li>
<li>
<p>Locate and select <code>Enable Integrated Windows Authentication</code></p>
</li>
<li>
<p>Tools &#8594; Options &#8594; Advanced &#8594; Security &#8594; Ok</p>
</li>
<li>
<p>Close IE then reopen and browse to your SPNEGO protected resource</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>You <strong>must</strong> use hostname and not the IP.
If you use the IP it will default to NTLM authentication.
The following conditions must be true for SPNEGO authentication to work:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>You must be within the Intranet Zone of the network</p>
</li>
<li>
<p>Access the server using a Hostname rather than IP</p>
</li>
<li>
<p>Integrated Windows Authentication in IE is enabled and/or the host is trusted in Firefox</p>
</li>
<li>
<p>The server is not local to the browser; it can&#8217;t be running on localhost</p>
</li>
<li>
<p>The client&#8217;s Kerberos system is authenticated to a domain controller</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect2">
<h3 id="openid-support"><a class="anchor" href="#openid-support"></a><a class="link" href="#openid-support">OpenID Support</a></h3>
<div class="sect3">
<h4 id="_external-setup"><a class="anchor" href="#_external-setup"></a><a class="link" href="#_external-setup">External Setup</a></h4>
<div class="sect4">
<h5 id="_registering-an-app-with-openid-provider"><a class="anchor" href="#_registering-an-app-with-openid-provider"></a><a class="link" href="#_registering-an-app-with-openid-provider">Registering an App with OpenID Provider</a></h5>
<div class="paragraph">
<p>You must register the app with an OpenID Provider such as <a href="https://developers.google.com/identity/protocols/OpenIDConnect#authenticatingtheuser">Google</a> or <a href="https://images-na.ssl-images-amazon.com/images/G/01/lwa/dev/docs/website-developer-guide.<em>TTH</em>.pdf">Amazon.</a>
This will give you a Client ID and Client Secret.
Once set up you must also register all the possible URI&#8217;s for your webapp with the path <code>/j_security_check</code> so that the OpenId Provider will allow redirection back to the webapp.</p>
</div>
<div class="paragraph">
<p>These may look like</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code><a href="http://localhost:8080/openid-webapp/j_security_check" class="bare">http://localhost:8080/openid-webapp/j_security_check</a></code></p>
</li>
<li>
<p><code><a href="https://example.com/j_security_check" class="bare">https://example.com/j_security_check</a></code></p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_distribution-configuration"><a class="anchor" href="#_distribution-configuration"></a><a class="link" href="#_distribution-configuration">Distribution Configuration</a></h4>
<div class="sect4">
<h5 id="_openid-provider-configuration"><a class="anchor" href="#_openid-provider-configuration"></a><a class="link" href="#_openid-provider-configuration">OpenID Provider Configuration</a></h5>
<div class="paragraph">
<p>To enable OpenID support, you first need to activate the <code>openid</code> module in your implementation.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ java -jar $JETTY_HOME/start.jar --add-to-start=openid</code></pre>
</div>
</div>
<div class="paragraph">
<p>To configure OpenID Authentication with Jetty you will need to specify the OpenID Provider&#8217;s issuer identifier (case sensitive URL using the <code>https</code> scheme) and the OAuth 2.0 Client ID and Client Secret.
If the OpenID Provider does not allow metadata discovery you will also need to specify the token endpoint and authorization endpoint of the OpenID Provider.
These can be set as properties in the <code>start.ini</code> or <code>start.d/openid.ini</code> files.</p>
</div>
</div>
<div class="sect4">
<h5 id="_webapp-specific-configuration-in-web-xml"><a class="anchor" href="#_webapp-specific-configuration-in-web-xml"></a><a class="link" href="#_webapp-specific-configuration-in-web-xml">WebApp Specific Configuration in web.xml</a></h5>
<div class="paragraph">
<p>The <code>web.xml</code> file needs some specific configuration to use OpenID.
There must be a <code>login-config</code> element with an <code>auth-method</code> value of <code>OPENID</code>, and a <code>realm-name</code> value of the exact URL string used to set the OpenID Provider.</p>
</div>
<div class="paragraph">
<p>To set the error page, an init param is set at <code>"org.eclipse.jetty.security.openid.error_page"</code>, its value should be a path relative to the webapp where authentication errors should be redirected.</p>
</div>
<div class="paragraph">
<p>Example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;login-config&gt;</span>
<span class="tag">&lt;auth-method&gt;</span>OPENID<span class="tag">&lt;/auth-method&gt;</span>
<span class="tag">&lt;realm-name&gt;</span>https://accounts.google.com<span class="tag">&lt;/realm-name&gt;</span>
<span class="tag">&lt;/login-config&gt;</span>
<span class="tag">&lt;context-param&gt;</span>
<span class="tag">&lt;param-name&gt;</span>org.eclipse.jetty.security.openid.error_page<span class="tag">&lt;/param-name&gt;</span>
<span class="tag">&lt;param-value&gt;</span>/error<span class="tag">&lt;/param-value&gt;</span>
<span class="tag">&lt;/context-param&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_embedded-configuration"><a class="anchor" href="#_embedded-configuration"></a><a class="link" href="#_embedded-configuration">Embedded Configuration</a></h4>
<div class="sect4">
<h5 id="_define-the-openidconfiguration-for-a-specific-openid-provider"><a class="anchor" href="#_define-the-openidconfiguration-for-a-specific-openid-provider"></a><a class="link" href="#_define-the-openidconfiguration-for-a-specific-openid-provider">Define the <code>OpenIdConfiguration</code> for a specific OpenID Provider.</a></h5>
<div class="paragraph">
<p>If the OpenID Provider allows metadata discovery then you can use.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">OpenIdConfiguration openIdConfig = <span class="keyword">new</span> OpenIdConfiguration(ISSUER, CLIENT_ID, CLIENT_SECRET);</code></pre>
</div>
</div>
<div class="paragraph">
<p>Otherwise you can manually enter the necessary information:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">OpenIdConfiguration openIdConfig = <span class="keyword">new</span> OpenIdConfiguration(ISSUER, TOKEN_ENDPOINT, AUTH_ENDPOINT, CLIENT_ID, CLIENT_SECRET);</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_configuring-an-openidloginservice"><a class="anchor" href="#_configuring-an-openidloginservice"></a><a class="link" href="#_configuring-an-openidloginservice">Configuring an <code>OpenIdLoginService</code></a></h5>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">LoginService loginService = <span class="keyword">new</span> OpenIdLoginService(openIdConfig);
securityHandler.setLoginService(loginService);</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_configuring-an-openidauthenticator-with-openidconfiguration-and-error-page-redirect"><a class="anchor" href="#_configuring-an-openidauthenticator-with-openidconfiguration-and-error-page-redirect"></a><a class="link" href="#_configuring-an-openidauthenticator-with-openidconfiguration-and-error-page-redirect">Configuring an <code>OpenIdAuthenticator</code> with <code>OpenIdConfiguration</code> and Error Page Redirect</a></h5>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="predefined-type">Authenticator</span> authenticator = <span class="keyword">new</span> OpenIdAuthenticator(openIdConfig, <span class="string"><span class="delimiter">&quot;</span><span class="content">/error</span><span class="delimiter">&quot;</span></span>);
securityHandler.setAuthenticator(authenticator);
servletContextHandler.setSecurityHandler(securityHandler);</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_usage-2"><a class="anchor" href="#_usage-2"></a><a class="link" href="#_usage-2">Usage</a></h5>
<div class="sect5">
<h6 id="_claims-and-access-token"><a class="anchor" href="#_claims-and-access-token"></a><a class="link" href="#_claims-and-access-token">Claims and Access Token</a></h6>
<div class="paragraph">
<p>Claims about the user can be found using attributes on the session attribute <code>"org.eclipse.jetty.security.openid.claims"</code>, and the full response containing the OAuth 2.0 Access Token can be found with the session attribute <code>"org.eclipse.jetty.security.openid.response"</code>.</p>
</div>
<div class="paragraph">
<p>Example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="predefined-type">Map</span>&lt;<span class="predefined-type">String</span>, <span class="predefined-type">Object</span>&gt; claims = (<span class="predefined-type">Map</span>)request.getSession().getAttribute(<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.openid.claims</span><span class="delimiter">&quot;</span></span>);
<span class="predefined-type">String</span> userId = claims.get(<span class="string"><span class="delimiter">&quot;</span><span class="content">sub</span><span class="delimiter">&quot;</span></span>);
<span class="predefined-type">Map</span>&lt;<span class="predefined-type">String</span>, <span class="predefined-type">Object</span>&gt; response = (<span class="predefined-type">Map</span>)request.getSession().getAttribute(<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.security.openid.response</span><span class="delimiter">&quot;</span></span>);
<span class="predefined-type">String</span> accessToken = response.get(<span class="string"><span class="delimiter">&quot;</span><span class="content">access_token</span><span class="delimiter">&quot;</span></span>);</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_scopes"><a class="anchor" href="#_scopes"></a><a class="link" href="#_scopes">Scopes</a></h4>
<div class="paragraph">
<p>The OpenID scope is always used but additional scopes can be requested which can give you additional resources or privileges.
For the Google OpenID Provider it can be useful to request the scopes <code>profile</code> and <code>email</code> which will give you additional user claims.</p>
</div>
<div class="paragraph">
<p>Additional scopes can be requested through the <code>start.ini</code> or <code>start.d/openid.ini</code> files, or with <code>OpenIdConfiguration.addScopes(&#8230;&#8203;);</code> in embedded code.</p>
</div>
</div>
<div class="sect3">
<h4 id="_roles"><a class="anchor" href="#_roles"></a><a class="link" href="#_roles">Roles</a></h4>
<div class="paragraph">
<p>If security roles are required they can be configured through a wrapped <code>LoginService</code> which is deferred to for role information by the <code>OpenIdLoginService</code>.</p>
</div>
<div class="paragraph">
<p>This can be configured in XML through <code>etc/openid-baseloginservice.xml</code> in the Distribution, or in embedded code using the constructor for the <code>OpenIdLoginService</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">LoginService wrappedLoginService = ...; <span class="comment">// Optional LoginService for Roles</span>
LoginService loginService = <span class="keyword">new</span> OpenIdLoginService(openIdConfig, wrappedLoginService);</code></pre>
</div>
</div>
<div class="paragraph">
<p>When using authorization roles, the setting <code>authenticateNewUsers</code> becomes significant.
If set to <code>true</code> users not found by the wrapped <code>LoginService</code> will still be authenticated but will have no roles.
If set to <code>false</code> those users will be not be allowed to authenticate and are redirected to the error page.
This setting is configured through the property <code>jetty.openid.authenticateNewUsers</code> in the <code>start.ini</code> or <code>start.d/openid.ini</code> file, or with <code>OpenIdLoginService.setAuthenticateNewUsers(&#8230;&#8203;);</code> in embedded code.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="startup"><a class="anchor" href="#startup"></a><a class="link" href="#startup">Starting Jetty</a></h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="startup-unix-service"><a class="anchor" href="#startup-unix-service"></a><a class="link" href="#startup-unix-service">Startup a Unix Service using jetty.sh</a></h3>
<div class="paragraph">
<p>The standalone Jetty distribution ships with a <code>bin/jetty.sh</code> script that can be used by various Unix distros (including OSX) to manage Jetty as a startup service.</p>
</div>
<div class="paragraph">
<p>This script is suitable for setting up Jetty as a service in Unix.</p>
</div>
<div class="sect3">
<h4 id="_quick-start-a-jetty-service"><a class="anchor" href="#_quick-start-a-jetty-service"></a><a class="link" href="#_quick-start-a-jetty-service">Quick-Start a Jetty Service</a></h4>
<div class="paragraph">
<p>The minimum steps to get Jetty to run as a Service include:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[/opt/jetty]# tar -zxf /home/user/downloads/jetty-home-10.0.10.tar.gz
[/opt/jetty]# cd jetty-home-10.0.10/
[/opt/jetty/jetty-home-10.0.10]# ls
bin lib modules resources start.jar
demo-base license-eplv10-aslv20.html notice.html start.d VERSION.txt
etc logs README.TXT start.ini webapps
[/opt/jetty/jetty-home-10.0.10]# cp bin/jetty.sh /etc/init.d/jetty
[/opt/jetty/jetty-home-10.0.10]# echo JETTY_HOME=`pwd` &gt; /etc/default/jetty
[/opt/jetty/jetty-home-10.0.10]# cat /etc/default/jetty
JETTY_HOME=/opt/jetty/jetty-home-10.0.10
[/opt/jetty/jetty-home-10.0.10]# service jetty start
Starting Jetty: OK Wed Nov 20 10:26:53 MST 2013</code></pre>
</div>
</div>
<div class="paragraph">
<p>From this demonstration we can see that Jetty started successfully as a Unix Service from the <code>/opt/jetty/jetty-home-10.0.10</code> directory.</p>
</div>
<div class="paragraph">
<p>This configuration works well but it is running Jetty as the root user.</p>
</div>
</div>
<div class="sect3">
<h4 id="_practical-setup-of-a-jetty-service"><a class="anchor" href="#_practical-setup-of-a-jetty-service"></a><a class="link" href="#_practical-setup-of-a-jetty-service">Practical Setup of a Jetty Service</a></h4>
<div class="paragraph">
<p>There are various ways this can be accomplished, mostly depending on your Unix environment (and possibly corporate policies).</p>
</div>
<div class="paragraph">
<p>The techniques outlined here assume an installation on Linux (demonstrated on Ubuntu 12.04.3 LTS).</p>
</div>
<div class="paragraph">
<p>Prepare some empty directories to work with.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># mkdir -p /opt/jetty
# mkdir -p /opt/web/mybase
# mkdir -p /opt/jetty/temp</code></pre>
</div>
</div>
<div class="paragraph">
<p>The directory purposes are as follows:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">/opt/jetty</dt>
<dd>
<p>Where the Jetty Distribution will be unpacked into</p>
</dd>
<dt class="hdlist1">/opt/web/mybase</dt>
<dd>
<p>Where your specific set of webapps will be located, including all of the configuration required of the server to make them operational.</p>
</dd>
<dt class="hdlist1">/opt/jetty/temp</dt>
<dd>
<p>This is the temporary directory assigned to Java by the Service Layer (this is what Java sees as the <code>java.io.tmpdir</code> System Property).</p>
<div class="paragraph">
<p>This is intentionally kept separate from the standard temp directory of <code>/tmp</code>, as this location doubles as the Servlet Spec work directory.
It is our experience that the standard temp directory is often managed by various cleanup scripts that wreak havoc on a long running Jetty server.</p>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Jetty 9.3 requires Java 8 (or greater) to run.
Make sure you have it installed.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># apt-get install openjdk-8-jdk</code></pre>
</div>
</div>
<div class="paragraph">
<p>Or download Java 8 from: <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html" class="bare">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># java -version
java version &quot;1.6.0_27&quot;
OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
# update-alternatives --list java
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 manual mode
Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode.
# java -version
java version &quot;1.7.0_25&quot;
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)</code></pre>
</div>
</div>
<div class="paragraph">
<p>It is recommended that you create a user to specifically run Jetty.
This user should have the minimum set of privileges needed to run Jetty.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># useradd --user-group --shell /bin/false --home-dir /opt/jetty/temp jetty</code></pre>
</div>
</div>
<div class="paragraph">
<p>This will create a user called <code>jetty</code>, belonging to the group called <code>jetty</code>, with no shell access (aka <code>/bin/false</code>), and home directory at <code>/opt/jetty/temp</code>.</p>
</div>
<div class="paragraph">
<p>Download a copy of the Jetty distribution from the <a href="#jetty-downloading">Official Eclipse Download Site</a></p>
</div>
<div class="paragraph">
<p>Unpack it into place.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">[/opt/jetty]# tar -zxf /home/user/Downloads/jetty-home-10.0.10.tar.gz
[/opt/jetty]# ls -F
jetty-home-10.0.10/
[/opt/jetty]# mkdir /opt/jetty/temp</code></pre>
</div>
</div>
<div class="paragraph">
<p>It might seem strange or undesirable to unpack the first portion of the jetty-home directory name too.
But starting with Jetty 9 the split between <code>${jetty.home}</code> and <code>${jetty.base}</code> allows for easier upgrades of Jetty itself while isolating your webapp specific configuration.
For more information on the Jetty home and base concepts see the section on managing a Jetty installation <a href="#startup-base-and-home">earlier in this Chapter.</a></p>
</div>
<div class="paragraph">
<p>The <code>/opt/jetty/temp</code> directory is created as a durable place for Jetty to use for temp and working directories.
Many Unix systems will periodically clean out the /tmp directory, this behavior is undesired in a Servlet container and has been known to cause problems.
This durable directory at <code>/opt/jetty/temp</code> solves for that behavior.</p>
</div>
<div class="paragraph">
<p>The directory at <code>/opt/web/mybase</code> is going to be a <code>${jetty.base}</code>, so lets configure it to hold your webapp and its configuration.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="paragraph">
<p>In past versions of Jetty, you would configure / modify / add to the <code>jetty-home</code> directory directly.
While this is still supported, we encourage you to setup a proper <code>${jetty.base}</code> directory, as it will benefit you with easier <code>jetty-home</code> upgrades in the future.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># cd /opt/web/mybase/
[/opt/web/mybase]# ls
[/opt/web/mybase]# java -jar /opt/jetty/jetty-home-10.0.10/start.jar \
--add-to-start=deploy,http,console-capture
INFO : webapp transitively enabled, ini template available with --add-to-start=webapp
INFO : server transitively enabled, ini template available with --add-to-start=server
INFO : security transitively enabled
INFO : servlet transitively enabled
INFO : console-capture initialized in ${jetty.base}/start.ini
INFO : http initialized in ${jetty.base}/start.ini
INFO : deploy initialized in ${jetty.base}/start.ini
MKDIR : ${jetty.base}/logs
MKDIR : ${jetty.base}/webapps
INFO : Base directory was modified
[/opt/web/mybase]# ls -F
start.ini webapps/</code></pre>
</div>
</div>
<div class="paragraph">
<p>At this point you have configured your <code>/opt/web/mybase</code> to enable the following modules:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">deploy</dt>
<dd>
<p>This is the module that will perform deployment of web applications (WAR files or exploded directories), or Jetty IoC XML context deployables, from the <code>/opt/web/mybase/webapps</code> directory.</p>
</dd>
<dt class="hdlist1">http</dt>
<dd>
<p>This sets up a single Connector that listens for basic HTTP requests.</p>
<div class="paragraph">
<p>See the created <code>start.ini</code> for configuring this connector.</p>
</div>
</dd>
<dt class="hdlist1">console-capture</dt>
<dd>
<p>When running Jetty as a service it is very important to have logging enabled.
This module will enable the basic STDOUT and STDERR capture logging to the <code>/opt/web/mybase/logs/</code> directory.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Additionally, the <code>webapp</code>, <code>server</code>, <code>security</code> and <code>servlet</code> modules were enabled as they are dependencies for other modules.</p>
</div>
<div class="paragraph">
<p>See <a href="#start-jar">[start-jar]</a> for more details and options on setting up and configuring a <code>${jetty.base}</code> directory.</p>
</div>
<div class="paragraph">
<p>Copy your war file into place.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># cp /home/user/projects/mywebsite.war /opt/web/mybase/webapps/</code></pre>
</div>
</div>
<div class="paragraph">
<p>Most service installations will want Jetty to run on port 80, now is the opportunity to change this from the default value of <code>8080</code> to <code>80</code>.</p>
</div>
<div class="paragraph">
<p>Edit the <code>/opt/web/mybase/start.ini</code> and change the <code>jetty.http.port</code> value.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># grep jetty.http.port /opt/web/mybase/start.ini
jetty.port=80</code></pre>
</div>
</div>
<div class="paragraph">
<p>Change the permissions on the Jetty distribution and webapp directories so that the user you created can access it.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># chown --recursive jetty /opt/jetty
# chown --recursive jetty /opt/web/mybase</code></pre>
</div>
</div>
<div class="paragraph">
<p>Next we need to make the Unix System aware that we have a new Jetty Service that can be managed by the standard <code>service</code> calls.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># cp /opt/jetty/jetty-home-10.0.10/bin/jetty.sh /etc/init.d/jetty
# echo &quot;JETTY_HOME=/opt/jetty/jetty-home-10.0.10&quot; &gt; /etc/default/jetty
# echo &quot;JETTY_BASE=/opt/web/mybase&quot; &gt;&gt; /etc/default/jetty
# echo &quot;TMPDIR=/opt/jetty/temp&quot; &gt;&gt; /etc/default/jetty</code></pre>
</div>
</div>
<div class="paragraph">
<p>Test out the configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># service jetty status
Checking arguments to Jetty:
START_INI = /opt/web/mybase/start.ini
JETTY_HOME = /opt/jetty/jetty-home-10.0.10
JETTY_BASE = /opt/web/mybase
JETTY_CONF = /opt/jetty/jetty-home-10.0.10/etc/jetty.conf
JETTY_PID = /var/run/jetty.pid
JETTY_START = /opt/jetty/jetty-home-10.0.10/start.jar
CLASSPATH =
JAVA = /usr/bin/java
JAVA_OPTIONS = -Djetty.state=/opt/web/mybase/jetty.state
-Djetty.logs=/opt/web/mybase/logs
-Djetty.home=/opt/jetty/jetty-home-10.0.10
-Djetty.base=/opt/web/mybase
-Djava.io.tmpdir=/opt/jetty/temp
JETTY_ARGS = console-capture.xml jetty-started.xml
RUN_CMD = /usr/bin/java
-Djetty.state=/opt/web/mybase/jetty.state
-Djetty.logs=/opt/web/mybase/logs
-Djetty.home=/opt/jetty/jetty-home-10.0.10
-Djetty.base=/opt/web/mybase
-Djava.io.tmpdir=/opt/jetty/temp
-jar /opt/jetty/jetty-home-10.0.10/start.jar
console-capture.xml
jetty-started.xml</code></pre>
</div>
</div>
<div class="paragraph">
<p>You now have a configured <code>${jetty.base}</code> in <code>/opt/web/mybase</code> and a <code>${jetty.home}</code> in <code>/opt/jetty/jetty-home-10.0.10</code>, along with the service level files necessary to start the service.</p>
</div>
<div class="paragraph">
<p>Test the service to make sure it starts up and runs successfully.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"># service jetty start
Starting Jetty: OK Wed Nov 20 12:35:28 MST 2013
# service jetty check
..(snip)..
Jetty running pid=2958
[/opt/web/mybase]# ps u 2958
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
jetty 2958 5.3 0.1 11179176 53984 ? Sl 12:46 0:00 /usr/bin/java -Djetty...</code></pre>
</div>
</div>
<div class="paragraph">
<p>You should now have your server running.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="startup-windows-service"><a class="anchor" href="#startup-windows-service"></a><a class="link" href="#startup-windows-service">Startup via Windows Service</a></h3>
<div class="paragraph">
<p>There are no components that ship with the Jetty Distribution to make it a formal Windows Service.</p>
</div>
<div class="paragraph">
<p>However, we recommend the use of <a href="https://commons.apache.org/proper/commons-daemon/procrun.html">Apache ProcRun&#8217;s Daemon</a>.</p>
</div>
<div class="paragraph">
<p>The techniques outlined here are based on Windows 7 (64-bit), using JDK 8 (64-bit), running on an Intel i7 architecture machine.</p>
</div>
<div class="paragraph">
<p>Prepare some empty directories to work with.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">C:\&gt; mkdir opt
C:\&gt; cd opt
C:\opt&gt; mkdir jetty
C:\opt&gt; mkdir logs
C:\opt&gt; mkdir myappbase
C:\opt&gt; mkdir temp
C:\opt&gt; dir
Volume in drive C has no label.
Volume Serial Number is DEAD-BEEF
Directory of C:\opt
11/21/2013 04:06 PM &lt;DIR&gt; .
11/21/2013 04:06 PM &lt;DIR&gt; ..
11/21/2013 04:06 PM &lt;DIR&gt; jetty
11/21/2013 04:06 PM &lt;DIR&gt; logs
11/21/2013 04:06 PM &lt;DIR&gt; myappbase
11/21/2013 04:06 PM &lt;DIR&gt; temp
0 File(s) 0 bytes</code></pre>
</div>
</div>
<div class="paragraph">
<p>The directory purposes are as follows:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">C:\opt</dt>
<dd>
<p>Where the service layer utilities, scripts, and binaries will eventually be.</p>
</dd>
<dt class="hdlist1">C:\opt\logs</dt>
<dd>
<p>Where the logs for the service layer will put its own logs.</p>
<div class="paragraph">
<p>Typically you will see the audit logs (install/update/delete), StdOutput, and StdError logs here.</p>
</div>
</dd>
<dt class="hdlist1">C:\opt\jetty</dt>
<dd>
<p>Where the Jetty Distribution will be unpacked into.</p>
</dd>
<dt class="hdlist1">C:\opt\myappbase</dt>
<dd>
<p>Where your specific set of webapps will be located, including all of the configuration required of the server to make them operational.</p>
</dd>
<dt class="hdlist1">C:\opt\temp</dt>
<dd>
<p>This is the temporary directory assigned to Java by the Service Layer (this is what Java sees as the <code>java.io.tmpdir</code> System Property).</p>
<div class="paragraph">
<p>This is intentionally kept separate from the standard temp directories of Windows, as this location doubles as the Servlet Spec work directory.</p>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Or download Java 8 from: <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html" class="bare">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">C:\opt&gt;java -version
java version &quot;1.7.0_45&quot;
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)</code></pre>
</div>
</div>
<div class="paragraph">
<p>Download a copy of the ZIP distribution from the <a href="#jetty-downloading">Official Eclipse Download Site</a></p>
</div>
<div class="paragraph">
<p>Extract the contents of the <code>jetty-home-10.0.10</code> directory to <code>C:\opt\jetty</code></p>
</div>
<div class="paragraph">
<p>Once complete, the contents of the <code>C:\opt\jetty</code> directory should look like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">C:\opt\jetty&gt;dir
Volume in drive C has no label.
Volume Serial Number is C8CF-820B
Directory of C:\opt\jetty
11/21/2013 12:13 PM &lt;DIR&gt; .
11/21/2013 12:13 PM &lt;DIR&gt; ..
11/21/2013 12:13 PM &lt;DIR&gt; bin
11/21/2013 12:13 PM &lt;DIR&gt; demo-base
11/21/2013 12:13 PM &lt;DIR&gt; etc
11/21/2013 12:13 PM &lt;DIR&gt; lib
11/21/2013 12:13 PM 30,012 license-eplv10-aslv20.html
11/21/2013 12:13 PM &lt;DIR&gt; logs
11/21/2013 12:13 PM &lt;DIR&gt; modules
11/21/2013 12:13 PM 6,262 notice.html
11/21/2013 12:13 PM 1,249 README.TXT
11/21/2013 12:13 PM &lt;DIR&gt; resources
11/21/2013 12:13 PM &lt;DIR&gt; start.d
11/21/2013 12:13 PM 2,126 start.ini
11/21/2013 12:13 PM 72,226 start.jar
11/21/2013 12:13 PM 341,784 VERSION.txt
11/21/2013 12:13 PM &lt;DIR&gt; webapps
6 File(s) 453,659 bytes
11 Dir(s) 306,711,420,928 bytes free</code></pre>
</div>
</div>
<div class="paragraph">
<p>Download a copy of the <a href="https://commons.apache.org/proper/commons-daemon/binaries.html">Apache ProcRun</a> native binaries.</p>
</div>
<div class="paragraph">
<p>You should have downloaded a file named <code>commons-daemon-1.0.15-bin-windows.zip</code> (the version might be different).
Open the ZIP file and extract the <code>prunmgr.exe</code> and <code>prunsrv.exe</code> files into the <code>C:\opt</code> directory.</p>
</div>
<div class="paragraph">
<p>Make sure to get the right version of <code>prunsrv.exe</code> for your environment.
The ZIP file has both 32 bit and 64 bit versions of this file.</p>
</div>
<div class="paragraph">
<p>Once you are complete, the contents of <code>C:\opt</code> directory should look like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">C:\opt&gt; dir
Volume in drive C has no label.
Volume Serial Number is DEAD-BEEF
Directory of C:\opt
11/21/2013 04:06 PM &lt;DIR&gt; .
11/21/2013 04:06 PM &lt;DIR&gt; ..
11/21/2013 04:06 PM &lt;DIR&gt; jetty
11/21/2013 04:06 PM &lt;DIR&gt; logs
11/21/2013 04:06 PM &lt;DIR&gt; myappbase
11/21/2013 04:06 PM &lt;DIR&gt; temp
11/21/2013 04:11 PM 104,448 prunmgr.exe
11/21/2013 04:11 PM 80,896 prunsrv.exe
2 File(s) 185,344 bytes</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now it&#8217;s time to setup your new <code>${jetty.base}</code> directory to have all of your WebApps and the configurations that they need.</p>
</div>
<div class="paragraph">
<p>We&#8217;ll start by specifying which modules we want to use (this will create a start.ini file and also create a few empty directories for you)</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">C:\opt\myappbase&gt;java -jar ..\jetty\start.jar --add-to-start=deploy,http,console-capture
WARNING: deploy initialised in ${jetty.base}\start.ini (appended)
WARNING: deploy enabled in ${jetty.base}\start.ini
MKDIR: ${jetty.base}\webapps
WARNING: server initialised in ${jetty.base}\start.ini (appended)
WARNING: server enabled in ${jetty.base}\start.ini
WARNING: http initialised in ${jetty.base}\start.ini (appended)
WARNING: http enabled in ${jetty.base}\start.ini
WARNING: server enabled in ${jetty.base}\start.ini
WARNING: logging initialised in ${jetty.base}\start.ini (appended)
WARNING: logging enabled in ${jetty.base}\start.ini
MKDIR: ${jetty.base}\logs
C:\opt\myappbase&gt;dir
Volume in drive C has no label.
Volume Serial Number is C8CF-820B
Directory of C:\opt\myappbase
11/21/2013 12:49 PM &lt;DIR&gt; .
11/21/2013 12:49 PM &lt;DIR&gt; ..
11/21/2013 12:49 PM &lt;DIR&gt; logs
11/21/2013 12:49 PM 1,355 start.ini
11/21/2013 12:49 PM &lt;DIR&gt; webapps
1 File(s) 1,355 bytes
4 Dir(s) 306,711,064,576 bytes free</code></pre>
</div>
</div>
<div class="paragraph">
<p>At this point you have configured your <code>C:\opt\myappbase</code> to enable the following modules:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">deploy</dt>
<dd>
<p>This is the module that will perform deployment of web applications (WAR files or exploded directories), or Jetty IoC XML context deployables, from the <code>C:\opt\myappbase\webapps</code> directory.</p>
</dd>
<dt class="hdlist1">http</dt>
<dd>
<p>This sets up a single Connector that listens for basic HTTP requests.</p>
<div class="paragraph">
<p>See the created <code>start.ini</code> for configuring this connector.</p>
</div>
</dd>
<dt class="hdlist1">logging</dt>
<dd>
<p>When running Jetty as a service it is very important to have logging enabled.
This module will enable the basic STDOUT and STDERR capture logging to the <code>C:\opt\myappbase\logs</code> directory.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>See the section on <a href="#start-jar">[start-jar]</a> for more details and options on setting up and configuring a <code>${jetty.base}</code> directory.</p>
</div>
<div class="paragraph">
<p>At this point you merely have to copy your WAR files into the <code>{$jetty.base}/webapps</code> directory.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">C:\opt\myappbase&gt; copy C:\projects\mywebsite.war webapps\</code></pre>
</div>
</div>
<div class="paragraph">
<p>At this point you should have your directories, Java, the Jetty distribution, and your webapp specifics setup and ready for operation.</p>
</div>
<div class="paragraph">
<p>We will use the <a href="https://commons.apache.org/proper/commons-daemon/binaries.html">Apache ProcRun&#8217;s prunsrv.exe</a> to install a Jetty Service.</p>
</div>
<div class="paragraph">
<p>The basic command line syntax is outlined in the link above.</p>
</div>
<div class="paragraph">
<p>A example <code>install-jetty-service.bat</code> is provided here as an example, based on the above directories.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="bat">@echo off
set SERVICE_NAME=JettyService
set JETTY_HOME=C:\opt\jetty
set JETTY_BASE=C:\opt\myappbase
set STOPKEY=secret
set STOPPORT=50001
set PR_INSTALL=C:\opt\prunsrv.exe
@REM Service Log Configuration
set PR_LOGPREFIX=%SERVICE_NAME%
set PR_LOGPATH=C:\opt\logs
set PR_STDOUTPUT=auto
set PR_STDERROR=auto
set PR_LOGLEVEL=Debug
@REM Path to Java Installation
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45
set PR_JVM=%JAVA_HOME%\jre\bin\server\jvm.dll
set PR_CLASSPATH=%JETTY_HOME%\start.jar;%JAVA_HOME%\lib\tools.jar
@REM JVM Configuration
set PR_JVMMS=128
set PR_JVMMX=512
set PR_JVMSS=4000
set PR_JVMOPTIONS=-Duser.dir=&quot;%JETTY_BASE%&quot;;-Djava.io.tmpdir=&quot;C:\opt\temp&quot;;-Djetty.home=&quot;%JETTY_HOME%&quot;;-Djetty.base=&quot;%JETTY_BASE%&quot;
@REM Startup Configuration
set JETTY_START_CLASS=org.eclipse.jetty.start.Main
set PR_STARTUP=auto
set PR_STARTMODE=java
set PR_STARTCLASS=%JETTY_START_CLASS%
set PR_STARTPARAMS=STOP.KEY=&quot;%STOPKEY%&quot;;STOP.PORT=%STOPPORT%
@REM Shutdown Configuration
set PR_STOPMODE=java
set PR_STOPCLASS=%JETTY_START_CLASS%
set PR_STOPPARAMS=--stop;STOP.KEY=&quot;%STOPKEY%&quot;;STOP.PORT=%STOPPORT%;STOP.WAIT=10
&quot;%PR_INSTALL%&quot; //IS/%SERVICE_NAME% ^
--DisplayName=&quot;%SERVICE_NAME%&quot; ^
--Install=&quot;%PR_INSTALL%&quot; ^
--Startup=&quot;%PR_STARTUP%&quot; ^
--LogPath=&quot;%PR_LOGPATH%&quot; ^
--LogPrefix=&quot;%PR_LOGPREFIX%&quot; ^
--LogLevel=&quot;%PR_LOGLEVEL%&quot; ^
--StdOutput=&quot;%PR_STDOUTPUT%&quot; ^
--StdError=&quot;%PR_STDERROR%&quot; ^
--JavaHome=&quot;%JAVA_HOME%&quot; ^
--Jvm=&quot;%PR_JVM%&quot; ^
--JvmMs=&quot;%PR_JVMMS%&quot; ^
--JvmMx=&quot;%PR_JVMMX%&quot; ^
--JvmSs=&quot;%PR_JVMSS%&quot; ^
--JvmOptions=%PR_JVMOPTIONS% ^
--Classpath=&quot;%PR_CLASSPATH%&quot; ^
--StartMode=&quot;%PR_STARTMODE%&quot; ^
--StartClass=&quot;%JETTY_START_CLASS%&quot; ^
--StartParams=&quot;%PR_STARTPARAMS%&quot; ^
--StopMode=&quot;%PR_STOPMODE%&quot; ^
--StopClass=&quot;%PR_STOPCLASS%&quot; ^
--StopParams=&quot;%PR_STOPPARAMS%&quot;
if not errorlevel 1 goto installed
echo Failed to install &quot;%SERVICE_NAME%&quot; service. Refer to log in %PR_LOGPATH%
goto end
:installed
echo The Service &quot;%SERVICE_NAME%&quot; has been installed
:end</code></pre>
</div>
</div>
<div class="paragraph">
<p>Configuration&#8217;s of note in this batch file:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">SERVICE_NAME</dt>
<dd>
<p>This is the name of the service that Windows sees.
The name in the Services window will show this name.</p>
</dd>
<dt class="hdlist1">STOPKEY</dt>
<dd>
<p>This is the secret key (password) for the ShutdownMonitor, used to issue a formal command to stop the server.</p>
</dd>
<dt class="hdlist1">STOPPORT</dt>
<dd>
<p>The port that the Shutdown Monitor listens on for the stop command.</p>
<div class="paragraph">
<p>If you have multiple Jetty servers on the same machine, this port will need to be different for each Service.</p>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Once you have run <code>prunsrv.exe //IS/&lt;service-name&gt;</code> (done for you in the above batch file) to install the service, you can use the standard Windows utilities to manage (start/stop/restart) the Jetty service.</p>
</div>
<div class="paragraph">
<p>Open the Service View and start your service.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="windows-service-jetty.png" alt="image" width="576"></span></p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="troubleshooting"><a class="anchor" href="#troubleshooting"></a><a class="link" href="#troubleshooting">Troubleshooting</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>This is a collection of helpful tricks and tips that we have come across to address odd issues that might arise.</p>
</div>
<div class="sect2">
<h3 id="troubleshooting-zip-exceptions"><a class="anchor" href="#troubleshooting-zip-exceptions"></a><a class="link" href="#troubleshooting-zip-exceptions">Troubleshooting Zip Exceptions</a></h3>
<div class="paragraph">
<p>A Zip exception occurs when Jetty rereads a Jar or WAR file.</p>
</div>
<div class="paragraph">
<p>The JVM maintains a cache of zip file indexes, and does not support hot replacement of zip files.
Thus if you redeploy a web application using the same WAR or Jar files, exceptions occur when Jetty rereads the jars.
See <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4774421">Oracle Bug 4774421</a> for more information.</p>
</div>
<div class="sect3">
<h4 id="remedy"><a class="anchor" href="#remedy"></a><a class="link" href="#remedy">Remedy</a></h4>
<div class="paragraph">
<p>The remedy is to avoid hot replacing Jar or WAR files, which can be difficult if you are using the
<a href="#configuring-specific-webapp-deployment">Webapp Provider</a>.
You can use the following techniques to reduce exposure to this issue:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Deploy unpacked classes in the <code>WEB-INF/classes</code> directory rather than as a Jar file under <code>WEB-INF/lib</code>.</p>
</li>
<li>
<p>Deploy all WAR and Jar files with a version number in their filename or path.
If the code changes, a new version number applies, avoiding the cache problem.</p>
</li>
<li>
<p>Deploy a packed WAR file with the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setExtractWAR(boolean)">setExtractWAR</a> option set to true.
This causes the WAR to be extracted to a <a href="#ref-temporary-directories">temporary directory</a> and thus to a new location.
This might not be sufficient if you want to hot-replace and re-extract the WAR, so you might also need to use <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setCopyWebInf(boolean)">WebAppContext.setCopyWebInf(true)</a>, which (re)copies just the WEB-INF directory to a different location.</p>
</li>
<li>
<p>Deploy an unpacked WAR file with the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setCopyWebDir(boolean)">setCopyWebDir</a> option set to true.
This causes the directory to be extracted to a new location.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>If you have problems with <a href="#troubleshooting-locked-files-on-windows">Windows file-locking</a> preventing static file editing (such as JSP or HTML), use the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/webapp/WebAppContext.html#setCopyWebDir(boolean)">WebAppContext .setCopyWebDir(true)</a> option.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="troubleshooting-locked-files-on-windows"><a class="anchor" href="#troubleshooting-locked-files-on-windows"></a><a class="link" href="#troubleshooting-locked-files-on-windows">Troubleshooting Locked Files on Windows</a></h3>
<div class="paragraph">
<p>Jetty buffers static content for webapps such as HTML files, CSS files, images, etc.
If you are using NIO connectors, Jetty uses memory-mapped files to do this.
The problem is that on Windows, memory mapping a file causes the file to lock, so that you cannot update or replace the file.
Effectively this means that you have to stop Jetty to update a file.</p>
</div>
<div class="sect3">
<h4 id="_remedy"><a class="anchor" href="#_remedy"></a><a class="link" href="#_remedy">Remedy</a></h4>
<div class="paragraph">
<p>Jetty provides a configuration switch for the <code>DefaultServlet</code> that enables or disables the use of memory-mapped files.
If you are running on Windows and are having file-locking problems, you should set this switch to disable memory-mapped file buffers.
Use one of the following options to configure the switch.</p>
</div>
<div class="sect4">
<h5 id="_using-override-web-xml"><a class="anchor" href="#_using-override-web-xml"></a><a class="link" href="#_using-override-web-xml">Using override-web.xml</a></h5>
<div class="paragraph">
<p>An <a href="#override-web-xml">override-web.xml</a> file can be placed in your webapp&#8217;s <code>WEB-INF</code> directory to change the default setting of the <code>DefaultServlet</code> for memory-mapped file buffers.
Create an <code>override-web.xml</code> file with appropriate headers for your version of the servlet specification, and place the following inside the <code>&lt;web-app&gt;</code> element:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;servlet&gt;</span>
<span class="tag">&lt;servlet-name&gt;</span>default<span class="tag">&lt;/servlet-name&gt;</span>
<span class="tag">&lt;init-param&gt;</span>
<span class="tag">&lt;param-name&gt;</span>useFileMappedBuffer<span class="tag">&lt;/param-name&gt;</span>
<span class="tag">&lt;param-value&gt;</span>false<span class="tag">&lt;/param-value&gt;</span>
<span class="tag">&lt;/init-param&gt;</span>
<span class="tag">&lt;/servlet&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_using-a-context-xml-file"><a class="anchor" href="#_using-a-context-xml-file"></a><a class="link" href="#_using-a-context-xml-file">Using a Context XML File</a></h5>
<div class="paragraph">
<p>You can create or update a context xml file that configures your webapp to apply the setting to disable memory-mapped file buffers.
Add the following to your context xml file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">setInitParameter</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>org.eclipse.jetty.servlet.Default.useFileMappedBuffer<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;Arg&gt;</span>false<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span></code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_using-the-jetty-maven-plugin"><a class="anchor" href="#_using-the-jetty-maven-plugin"></a><a class="link" href="#_using-the-jetty-maven-plugin">Using the Jetty Maven Plugin</a></h5>
<div class="paragraph">
<p>If you don&#8217;t want to use either of the other two solutions, you can configure the plugin directly to disable memory-mapped file buffers.
Add the following to the plugin&#8217;s configuration under the <code>&lt;webApp&gt;</code> element:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag">&lt;_initParams&gt;</span>
<span class="tag">&lt;org.eclipse.jetty.servlet.Default.useFileMappedBuffer&gt;</span>false<span class="tag">&lt;/org.eclipse.jetty.servlet.Default.useFileMappedBuffer&gt;</span>
<span class="tag">&lt;/_initParams&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_alternate-remedy"><a class="anchor" href="#_alternate-remedy"></a><a class="link" href="#_alternate-remedy">Alternate Remedy</a></h4>
<div class="paragraph">
<p>You can force a <code>WebAppContext</code> to always copy a web app directory on deployment.
The base directory of your web app (i.e. the root directory where your static content exists) will be copied to the <a href="#ref-temporary-directories">temp directory</a>.
Configure this in an xml file like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;New</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myWebAppContext</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.webapp.WebAppContext</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">contextPath</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>/<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">war</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>./webapps/fredapp<span class="tag">&lt;/Set&gt;</span>
<span class="tag">&lt;Set</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">copyWebDir</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>true<span class="tag">&lt;/Set&gt;</span>
.
.
<span class="tag">&lt;/New&gt;</span></code></pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Be careful with this option when using an explicitly set<a href="#ref-temp-directories">temp directory</a> name - as the name of the temp directory will not unique across redeployments, copying the static content into the same directory name each time may not avoid the locking problem.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
</div>
<div class="sect2">
<h3 id="preventing-memory-leaks"><a class="anchor" href="#preventing-memory-leaks"></a><a class="link" href="#preventing-memory-leaks">Preventing Memory Leaks</a></h3>
<div class="paragraph">
<p>If you have memory leaks, and you have thoroughly investigated tools like jconsole, yourkit, jprofiler, jvisualvm or any of the other profiling and analysis tools, and you can eliminate your code as the source of the problem, read the following sections about how to prevent memory leaks in your application.</p>
</div>
<div class="sect3">
<h4 id="preventing-webapp-classloader-pinning"><a class="anchor" href="#preventing-webapp-classloader-pinning"></a><a class="link" href="#preventing-webapp-classloader-pinning">Preventing WebApp Classloader Pinning</a></h4>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
This feature is available for Jetty 7.6.6 and later.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>Code that keeps references to a webapp classloader can cause memory leaks.
These leaks fall generally into two categories: static fields and daemon threads.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A static field is initialized with the value of the classloader, which happens to be a webapp classloader; as Jetty undeploys and redeploys the webapp, the static reference lives on, meaning garbage collecting cannot occur for the webapp classloader.</p>
</li>
<li>
<p>When Jetty starts as a daemon thread and is outside the lifecycle of the webapp, threads have references to the context classloader that created them, leading to a memory leak if that classloader belongs to a webapp.
For a good discussion of the issue see <a href="http://cdivilly.wordpress.com/tag/sun-awt-appcontext/">Anatomy of a PermGen Memory Leak.</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>We provide a number of <a href="https://www.eclipse.org/jetty/javadoc/jetty-10//org/eclipse/jetty/util/preventers/package-summary.html">workaround classes</a> that preemptively invoke the problematic code with the Jetty classloader, thereby ensuring the webapp classloader is not pinned.
Be aware that since some of the problematic code creates threads, you should be selective about which preventers you enable, and use only those that are specific to your application.</p>
</div>
<div class="sect4">
<h5 id="preventers-table"><a class="anchor" href="#preventers-table"></a><a class="link" href="#preventers-table">Preventers</a></h5>
<div class="paragraph">
<p>Jetty includes the following preventers.</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Preventer Name</th>
<th class="tableblock halign-left valign-top">Problem Addressed</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">AppContextLeakPreventer</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The call to <code>AppContext.getAppContext()</code> keeps a static reference to the context classloader. The JRE can invoke AppContext in many different places.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">AWTLeakPreventer</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The <code>java.awt.Toolkit</code> class has a static field that is the default toolkit.
Creating the default toolkit causes the creation of an <code>EventQueue</code>, which has a classloader field initialized with the thread context class loader.
See <a href="https://issues.jboss.org/browse/AS7-3733">JBoss bug AS7-3733.</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">DOMLeakPreventer</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">DOM parsing can cause the webapp classloader to be pinned, due to the static field ` RuntimeException` of <code>com.sun.org.apache.xerces.internal.parsers.AbstractDOMParser.</code> <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6916498">Oracle bug 6916498</a> specifically mentions that a heap dump might not identify the GCRoot as the uncollected loader, making it difficult to identify the cause of the leak.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">DriverManagerLeakPreventer</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The number of threads dedicated to accepting incoming connections.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">GCThreadLeakPreventer</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Calls to <code>sun.misc.GC.requestLatency</code> create a daemon thread that keeps a reference to the context classloader.
A known caller of this method is the RMI impl. See <a href="http://stackoverflow.com/questions/6626680/does-java-garbage-collection-log-entry-full-gc-system-mean-some-class-called">Stackoverflow: Does java garbage collection log entry 'Full GC system' mean some class
called System.gc()?</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java2DLeakPreventer</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>sun.java2d.Disposer</code> keeps a reference to the classloader.
See <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=51687">ASF bug 51687.</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">LDAPLeakPreventer</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If <code>com.sun.jndi.LdapPoolManager</code> class is loaded and the system property ` com.sun.jndi.ldap.connect.pool.timeout` is set to a nonzero value, a daemon thread starts and keeps a reference to the context classloader.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">LoginConfigurationLeakPreventer</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The <code>javax.security.auth.login.Configuration</code> class keeps a static reference to the thread context classloader.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">SecurityProviderLeakPreventer</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Some security providers, such as <code>sun.security.pkcs11.SunPKCS11</code> start a deamon thread that traps the thread context classloader.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect4">
<h5 id="configuring-preventers"><a class="anchor" href="#configuring-preventers"></a><a class="link" href="#configuring-preventers">Configuring Preventers</a></h5>
<div class="paragraph">
<p>You can individually enable each preventer by adding an instance to a Server with the ` addBean(Object)` call. Here&#8217;s an example of how to do it in code with the <code>org.eclipse.jetty.util.preventers.AppContextLeakPreventer</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Server server = <span class="keyword">new</span> Server();
server.addBean(<span class="keyword">new</span> AppContextLeakPreventer());</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can add the equivalent in code to the <code>$JETTY_HOME/etc/jetty.xml</code> file or any jetty xml file that is configuring a Server instance.
Be aware that if you have more than one Server instance in your JVM, you should configure these preventers on just <em>one</em> of them.
Here&#8217;s the example from code put into xml:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;Configure</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Server</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.server.Server</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Call</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">addBean</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
<span class="tag">&lt;Arg&gt;</span>
<span class="tag">&lt;New</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">org.eclipse.jetty.util.preventers.AppContextLeakPreventer</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
<span class="tag">&lt;/Arg&gt;</span>
<span class="tag">&lt;/Call&gt;</span>
<span class="tag">&lt;/Configure&gt;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="jsp-bugs"><a class="anchor" href="#jsp-bugs"></a><a class="link" href="#jsp-bugs">JSP Bugs: Permgen Problems</a></h4>
<div class="paragraph">
<p>The JSP engine in Jetty is Jasper.
This was originally developed under the Apache Tomcat project, but over time many different project have forked it.
All Jetty versions up to 6 used Apache-based Jasper exclusively, with Jetty 6 using Apache Jasper only for JSP 2.0.
With the advent of JSP 2.1, Jetty 6 switched to using Jasper from Sun&#8217;s <a href="https://glassfish.java.net/">Glassfish</a> project, which is now the reference implementation.</p>
</div>
<div class="paragraph">
<p>All forks of Jasper suffer from a problem whereby using JSP tag files puts the permgen space under pressure.
This is because of the classloading architecture of the JSP implementation.
Each JSP file is effectively compiled and its class loaded in its own classloader to allow for hot replacement.
Each JSP that contains references to a tag file compiles the tag if necessary and then loads it using its own classloader.
If you have many JSPs that refer to the same tag file, the tag&#8217;s class is loaded over and over again into permgen space, once for each JSP.
See <a href="http://java.net/jira/browse/GLASSFISH-3963">Glassfish bug 3963</a> and <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=43878">Apache bug 43878.</a>
The Apache Tomcat project has already closed this bug with status WON&#8217;T FIX, however the Glassfish folks still have the bug open and have scheduled it to be fixed.
When the fix becomes available, the Jetty project will pick it up and incorporate into our release program.</p>
</div>
</div>
<div class="sect3">
<h4 id="jvm-bugs"><a class="anchor" href="#jvm-bugs"></a><a class="link" href="#jvm-bugs">JVM Bugs</a></h4>
<div class="paragraph">
<p>This section describes garbage collection and direct ByteBuffer problems.</p>
</div>
<div class="sect4">
<h5 id="jvm-garbage-collection-problems"><a class="anchor" href="#jvm-garbage-collection-problems"></a><a class="link" href="#jvm-garbage-collection-problems">Garbage Collection Problems</a></h5>
<div class="paragraph">
<p>One symptom of a cluster of JVM related memory issues is the OOM exception accompanied by a message such as <code>java.lang.OutOfMemoryError: requested xxxx bytes for xxx.
Out of swap space?</code></p>
</div>
<div class="paragraph">
<p><a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4697804">Oracle bug 4697804</a> describes how this can happen in the scenario when the garbage collector needs to allocate a bit more space during its run and tries to resize the heap, but fails because the machine is out of swap space.
One suggested work around is to ensure that the JVM never tries to resize the heap, by setting min heap size to max heap size:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">java -Xmx1024m -Xms1024m</code></pre>
</div>
</div>
<div class="paragraph">
<p>Another workaround is to ensure you have configured sufficient swap space on your device to accommodate all programs you are running concurrently.</p>
</div>
</div>
<div class="sect4">
<h5 id="direct-byte-buffers"><a class="anchor" href="#direct-byte-buffers"></a><a class="link" href="#direct-byte-buffers">Direct ByteBuffers</a></h5>
<div class="paragraph">
<p>Exhausting native memory is another issue related to JVM bugs.
The symptoms to look out for are the process size growing, but heap use remaining relatively constant.
Both the JIT compiler and nio ByteBuffers can consume native memory.
<a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6210541">Oracle bug 6210541</a> discusses a still-unsolved problem whereby the JVM itself allocates a direct ByteBuffer in some circumstances while the system never garbage collects, effectively eating native memory.
Guy Korland&#8217;s blog discusses this problem <a href="http://www.jroller.com/gkorland/entry/java_s_memory_isn_t">here</a> and <a href="http://www.jroller.com/gkorland/entry/java_s_memory_managment_is">here.</a>
As the JIT compiler consumes native memory, the lack of available memory may manifest itself in the JIT as OutOfMemory exceptions such as <code>Exception in thread "CompilerThread0" java.lang.OutOfMemoryError: requested xxx bytes for ChunkPool::allocate. Out of swap
space?</code></p>
</div>
<div class="paragraph">
<p>By default, Jetty allocates and manages its own pool of direct ByteBuffers for io if you configure the nio SelectChannelConnector.
It also allocates MappedByteBuffers to memory-map static files via the DefaultServlet settings.
However, you could be vulnerable to this JVM ByteBuffer allocation problem if you have disabled either of these options.
For example, if you&#8217;re on Windows, you may have disabled the use of memory-mapped buffers for the static file cache on the DefaultServlet to avoid the file-locking problem.</p>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="troubleshooting-slow-deployment"><a class="anchor" href="#troubleshooting-slow-deployment"></a><a class="link" href="#troubleshooting-slow-deployment">Troubleshooting Slow Deployment</a></h3>
<div class="paragraph">
<p>After upgrading to a version of Jetty that supports Servlet Spec 3.0 or above, enabling some new modules, or introducing some new jars to your webapp, you notice that your deployment time is increased.
This could be due to scanning for classes caused by a ServletContainerInitializer.</p>
</div>
<div class="paragraph">
<p>As documented in the section on <a href="#using-annotations">Using Annotations</a>, even if your webapp has set <code>metadata-complete=true</code> in web.xml, all jars within your webapp may still be scanned due to one or more ServletContainerInitializers that have a <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/annotation/HandlesTypes.html">&#64;HandlesTypes</a> annotation listing the names of classes in which it is interested.</p>
</div>
<div class="paragraph">
<p>There are 3 ways to speed up deployment time:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>limit which ServletContainerInitializers to include</p>
</li>
<li>
<p>limit which jars to scan</p>
</li>
<li>
<p>limit the scan to the first deployment only</p>
</li>
</ul>
</div>
<div class="sect3">
<h4 id="_remedies"><a class="anchor" href="#_remedies"></a><a class="link" href="#_remedies">Remedies</a></h4>
<div class="sect4">
<h5 id="_limit-which-servletcontainerinitializers-to-execute"><a class="anchor" href="#_limit-which-servletcontainerinitializers-to-execute"></a><a class="link" href="#_limit-which-servletcontainerinitializers-to-execute">Limit Which ServletContainerInitializers to Execute</a></h5>
<div class="paragraph">
<p>As documented in the section <a href="#excluding-scis">Excluding ServletContainerInitializers</a>, you can provide a context attribute that defines a pattern of ServletContainerInitializer (SCI) class names to ignore.
These SCIs will not be examined for <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/annotation/HandlesTypes.html">&#64;HandlesTypes</a> and will not be executed.
This is useful if you have included a 3rd party jar that has a SCI on which your code does not rely.</p>
</div>
</div>
<div class="sect4">
<h5 id="_limit-which-jars-to-scan"><a class="anchor" href="#_limit-which-jars-to-scan"></a><a class="link" href="#_limit-which-jars-to-scan">Limit Which Jars to Scan</a></h5>
<div class="paragraph">
<p>As documented in the section <a href="#jars-scanned-for-annotations">Jars Scanned for Annotations</a>, you can explicitly define which jars to include in the scanning process.
This is helpful if you have a lot of jars in your webapp, and you know that they do not contain any classes referenced by an @HandlesTypes annotation on a ServletContainerInitializer that will be executed.</p>
</div>
</div>
<div class="sect4">
<h5 id="_limit-scanning-to-first-deployment-only-quickstart"><a class="anchor" href="#_limit-scanning-to-first-deployment-only-quickstart"></a><a class="link" href="#_limit-scanning-to-first-deployment-only-quickstart">Limit Scanning to First Deployment Only (Quickstart)</a></h5>
<div class="paragraph">
<p>The <a href="#quickstart-webapp">quickstart mechanism</a> will do a normal deployment - obeying any limits on SCIs and jars to scan as documented here - the first time the webapp is deployed only.
Subsequent deployments will re-use the information discovered during the first deployment.
This is useful if you cannot limit the scan significantly by using any of the mechanisms described here, but you don&#8217;t want to incur the cost of scanning on every redeployment.
The <a href="#quickstart-webapp">quickstart mechanism</a> and how to use it is described <a href="#quickstart-webapp">here</a>.</p>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="security-reports"><a class="anchor" href="#security-reports"></a><a class="link" href="#security-reports">Jetty Security Reports</a></h3>
<div class="sect3">
<h4 id="_list-of-security-reports"><a class="anchor" href="#_list-of-security-reports"></a><a class="link" href="#_list-of-security-reports">List of Security Reports</a></h4>
<div class="paragraph">
<p>A current list of Jetty security reports can be viewed on the <a href="https://www.eclipse.org/jetty/security-reports.html">Project Home Page.</a></p>
</div>
</div>
<div class="sect3">
<h4 id="_reporting-security-issues"><a class="anchor" href="#_reporting-security-issues"></a><a class="link" href="#_reporting-security-issues">Reporting Security Issues</a></h4>
<div class="paragraph">
<p>There are a number of avenues for reporting security issues to the Jetty project available.</p>
</div>
<div class="paragraph">
<p>If the issue is directly related to Jetty itself then reporting to the Jetty developers is encouraged.
The most direct method is to mail <em>security@webtide.com</em>.
Since Webtide is comprised of the active committers of the Jetty project this is our preferred reporting method.
We are generally flexible in how we work with reporters of security issues but we reserve the right to act in the interests of the Jetty project in all circumstances.</p>
</div>
<div class="paragraph">
<p>If the issue is related to Eclipse or its Jetty integration then we encourage you to reach out to <em>security@eclipse.org</em>.</p>
</div>
<div class="paragraph">
<p>If the issue is related to integrations with Jetty we are happy to work with you to identify the proper entity and either of the approaches above is fine.</p>
</div>
<div class="paragraph">
<p>We prefer that security issues are reported directly to Jetty developers as opposed through GitHub Issues since it currently has <strong>no</strong> facility to tag issues as <em>private</em>.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="watchservice"><a class="anchor" href="#watchservice"></a><a class="link" href="#watchservice">Java WatchService</a></h3>
<div class="paragraph">
<p>The JVM <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/file/WatchService.html"><code>WatchService</code></a> is in place to monitor objects like a directory for changes, and then update it&#8217;s contents and notify the application of those changes.
This service is useful for features like <a href="#hot-deployment">Hot Deployment</a>.
When a change is detected, the <code>WatchService</code> will enter a "quiet time" where it is waiting for the change (or changes) to be made and completed before notifying the application of the change.</p>
</div>
<div class="paragraph">
<p>Example:
A new war file is copied into <code>/webapps</code>.
The <code>WatchService</code> can (depending on implementation) see that the file was created (which is registered as an event!, and that its growing in size (another event).
With the quiet time, each of the events are gated behind that timeout before the aggregated events are sent to the application.</p>
</div>
<div class="paragraph">
<p>While some operating systems such as Windows have a native value for this quiet time, not all do, notably OSX.
At the core this is a limitation of the JVM&#8217;s FileSystem-specific implementation, but one that has been raised to the <a href="https://bugs.openjdk.java.net/browse/JDK-7133447">attention of the project.</a></p>
</div>
<div class="sect3">
<h4 id="_remedy-2"><a class="anchor" href="#_remedy-2"></a><a class="link" href="#_remedy-2">Remedy</a></h4>
<div class="paragraph">
<p>To help offset the delay in systems like OSX, Jetty defaults the value for non-native implementations to a <a href="https://github.com/eclipse/jetty.project/tree/jetty-9.4.x/jetty-util/src/main/java/org/eclipse/jetty/util/PathWatcher.java#L1431">time of 5000ms.</a>
Using values lower than 5000ms is not recommended and has shown to frequently fail.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="optimizing"><a class="anchor" href="#optimizing"></a><a class="link" href="#optimizing">Optimizing Jetty</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>There are many ways to optimize Jetty which vary depending on the situation.
Are you trying to optimize for number of requests within a given amount of time?
Are you trying to optimize the serving of static content?
Do you have a large bit of hardware that you want to give entirely over to Jetty to use to its heart&#8217;s delight?
This chapter examines a few of the many different ways to optimize Jetty.</p>
</div>
<div class="sect2">
<h3 id="garbage-collection"><a class="anchor" href="#garbage-collection"></a><a class="link" href="#garbage-collection">Garbage Collection</a></h3>
<div class="paragraph">
<p>Tuning the JVM garbage collection (GC) can greatly improve the performance of the JVM where Jetty and your application are running.
Optimal tuning of the GC depends on the behavior of the application(s) and requires detailed analysis, but there are general recommendations to follow to at least obtain comprehensive GC logs that can be later analyzed.</p>
</div>
<div class="paragraph">
<p>See official <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/">Java 8</a> and <a href="https://docs.oracle.com/javase/9/gctuning/introduction-garbage-collection-tuning.htm">Java 9</a> Garbage Collection documentation for further assistance.</p>
</div>
<div class="sect3">
<h4 id="garbage-collection-logging-configuration"><a class="anchor" href="#garbage-collection-logging-configuration"></a><a class="link" href="#garbage-collection-logging-configuration">Garbage Collection Logging Configuration</a></h4>
<div class="paragraph">
<p>These options are general to OpenJDK (and therefore also for the Oracle JVM).
They provide good information about the GC activity of your JVM, producing logs that can later be analyzed to perform finer tuning.</p>
</div>
<div class="listingblock">
<div class="title">JDK 8 Garbage Collection Logging Configuration</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">-Xloggc:/path/to/myjettybase/logs/gc.log
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-XX:+ParallelRefProcEnabled
-XX:+PrintReferenceGC
-XX:+PrintTenuringDistribution
-XX:+PrintAdaptiveSizePolicy</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">JDK 9 Garbage Collection Logging Configuration</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">Xlog:gc*,ergo*=trace,ref*=debug,age*=trace:file=/path/to/myjettybase/logs/gc.log:time,level,tags</code></pre>
</div>
</div>
<div class="paragraph">
<p>There are not many recommended options for GC that can apply to all users.
However, the most obvious one is to disable explicit GC (this is performed regularly by RMI and can introduce an abnormal amount of GC pauses).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">-XX:+DisableExplicitGC</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="high-load"><a class="anchor" href="#high-load"></a><a class="link" href="#high-load">High Load</a></h3>
<div class="paragraph">
<p>Configuring Jetty for high load, whether for load testing or for production, requires that the operating system, the JVM, Jetty, the application, the network and the load generation all be tuned.</p>
</div>
<div class="sect3">
<h4 id="_load-generation-for-load-testing"><a class="anchor" href="#_load-generation-for-load-testing"></a><a class="link" href="#_load-generation-for-load-testing">Load Generation for Load Testing</a></h4>
<div class="paragraph">
<p>Machines handling load generation must have their OS, JVM, etc., tuned just as much as the server machines.</p>
</div>
<div class="paragraph">
<p>The load generation should not be over the local network on the server machine, as this has unrealistic performance and latency as well as different packet sizes and transport characteristics.</p>
</div>
<div class="paragraph">
<p>The load generator should generate a realistic load.
Avoid the following pitfalls:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A common mistake is that load generators often open relatively few connections that are extremely busy sending as many requests as possible over each connection.
This causes the measured throughput to be limited by request latency (see <a href="http://blogs.webtide.com/gregw/entry/lies_damned_lies_and_benchmarks">Lies, Damned Lies and Benchmarks</a> for an analysis of such an issue).</p>
</li>
<li>
<p>Another common mistake is to use TCP/IP for a single request, and to open many, many short-lived connections.
This often results in accept queues filling and limitations due to file descriptor and/or port starvation.</p>
</li>
<li>
<p>A load generator should model the traffic profile from the normal clients of the server.
For browsers, this is often between two and six connections that are mostly idle and that are used in sporadic bursts with read times in between.
The connections are typically long held HTTP/1.1 connections.</p>
</li>
<li>
<p>Load generators should be written in asynchronously so that a limited number of threads does not restrict the maximum number of users that can be simulated.
If the generator is not asynchronous, a thread pool of 2000 may only be able to simulate 500 or fewer users.
The Jetty <code>HttpClient</code> is an ideal choice for building a load generator as it is asynchronous and can simulate many thousands of connections (see the CometD Load Tester for a good example of a realistic load generator).</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="_operating-system-tuning"><a class="anchor" href="#_operating-system-tuning"></a><a class="link" href="#_operating-system-tuning">Operating System Tuning</a></h4>
<div class="paragraph">
<p>Both the server machine and any load generating machines need to be tuned to support many TCP/IP connections and high throughput.</p>
</div>
<div class="sect4">
<h5 id="_linux"><a class="anchor" href="#_linux"></a><a class="link" href="#_linux">Linux</a></h5>
<div class="paragraph">
<p>Linux does a reasonable job of self-configuring TCP/IP, but there are a few limits and defaults that you should increase.
You can configure most of these in <code>/etc/security/limits.conf</code> or via <code>sysctl</code>.</p>
</div>
<div class="sect5">
<h6 id="_tcp-buffer-sizes"><a class="anchor" href="#_tcp-buffer-sizes"></a><a class="link" href="#_tcp-buffer-sizes">TCP Buffer Sizes</a></h6>
<div class="paragraph">
<p>You should increase TCP buffer sizes to at least 16MB for 10G paths and tune the auto-tuning (keep in mind that you need to consider buffer bloat).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ sysctl -w net.core.rmem_max=16777216
$ sysctl -w net.core.wmem_max=16777216
$ sysctl -w net.ipv4.tcp_rmem=&quot;4096 87380 16777216&quot;
$ sysctl -w net.ipv4.tcp_wmem=&quot;4096 16384 16777216&quot;</code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="_queue-sizes"><a class="anchor" href="#_queue-sizes"></a><a class="link" href="#_queue-sizes">Queue Sizes</a></h6>
<div class="paragraph">
<p><code>net.core.somaxconn</code> controls the size of the connection listening queue.
The default value is 128.
If you are running a high-volume server and connections are getting refused at a TCP level, you need to increase this value.
This setting can take a bit of finesse to get correct: if you set it too high, resource problems occur as it tries to notify a server of a large number of connections, and many remain pending, but if you set it too low, refused connections occur.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen"> $ sysctl -w net.core.somaxconn=4096</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>net.core.netdev_max_backlog</code> controls the size of the incoming packet queue for upper-layer (Java) processing.
The default (2048) may be increased and other related parameters adjusted with:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ sysctl -w net.core.netdev_max_backlog=16384
$ sysctl -w net.ipv4.tcp_max_syn_backlog=8192
$ sysctl -w net.ipv4.tcp_syncookies=1</code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="_ports"><a class="anchor" href="#_ports"></a><a class="link" href="#_ports">Ports</a></h6>
<div class="paragraph">
<p>If many outgoing connections are made (for example, on load generators), the operating system might run low on ports.
Thus it is best to increase the port range, and allow reuse of sockets in <code>TIME_WAIT</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ sysctl -w net.ipv4.ip_local_port_range=&quot;1024 65535&quot;
$ sysctl -w net.ipv4.tcp_tw_recycle=1</code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="_file-descriptors"><a class="anchor" href="#_file-descriptors"></a><a class="link" href="#_file-descriptors">File Descriptors</a></h6>
<div class="paragraph">
<p>Busy servers and load generators may run out of file descriptors as the system defaults are normally low.
These can be increased for a specific user in <code>/etc/security/limits.conf</code>:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>theusername hard nofile 40000
theusername soft nofile 40000</pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="_congestion-control"><a class="anchor" href="#_congestion-control"></a><a class="link" href="#_congestion-control">Congestion Control</a></h6>
<div class="paragraph">
<p>Linux supports pluggable congestion control algorithms.
To get a list of congestion control algorithms that are available in your kernel run:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ sysctl net.ipv4.tcp_available_congestion_control</code></pre>
</div>
</div>
<div class="paragraph">
<p>If cubic and/or htcp are not listed, you need to research the control algorithms for your kernel.
You can try setting the control to cubic with:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="screen">$ sysctl -w net.ipv4.tcp_congestion_control=cubic</code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="_mac-os"><a class="anchor" href="#_mac-os"></a><a class="link" href="#_mac-os">Mac OS</a></h6>
<div class="paragraph">
<p>Tips welcome.</p>
</div>
</div>
<div class="sect5">
<h6 id="_windows"><a class="anchor" href="#_windows"></a><a class="link" href="#_windows">Windows</a></h6>
<div class="paragraph">
<p>Tips welcome.</p>
</div>
</div>
<div class="sect5">
<h6 id="_network-tuning"><a class="anchor" href="#_network-tuning"></a><a class="link" href="#_network-tuning">Network Tuning</a></h6>
<div class="paragraph">
<p>Intermediaries such as nginx can use a non-persistent HTTP/1.0 connection.
Make sure to use persistent HTTP/1.1 connections.</p>
</div>
</div>
<div class="sect5">
<h6 id="_jvm-tuning"><a class="anchor" href="#_jvm-tuning"></a><a class="link" href="#_jvm-tuning">JVM Tuning</a></h6>
<div class="ulist">
<ul>
<li>
<p>Tune the <a href="#tuning-examples">Garbage Collection</a></p>
</li>
<li>
<p>Allocate sufficient memory</p>
</li>
<li>
<p>Use the -server option</p>
</li>
<li>
<p>Jetty Tuning</p>
</li>
</ul>
</div>
</div>
<div class="sect5">
<h6 id="_acceptors"><a class="anchor" href="#_acceptors"></a><a class="link" href="#_acceptors">Acceptors</a></h6>
<div class="paragraph">
<p>The standard rule of thumb for the number of Accepters to configure is one per CPU on a given machine.</p>
</div>
</div>
<div class="sect5">
<h6 id="_low-resource-limits"><a class="anchor" href="#_low-resource-limits"></a><a class="link" href="#_low-resource-limits">Low Resource Limits</a></h6>
<div class="paragraph">
<p>Must not be configured for less than the number of expected connections.</p>
</div>
</div>
<div class="sect5">
<h6 id="_thread-pool"><a class="anchor" href="#_thread-pool"></a><a class="link" href="#_thread-pool">Thread Pool</a></h6>
<div class="paragraph">
<p>Configure with goal of limiting memory usage maximum available.
Typically this is &gt;50 and &lt;500</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="limit-load"><a class="anchor" href="#limit-load"></a><a class="link" href="#limit-load">Limiting Load</a></h3>
<div class="paragraph">
<p>To achieve optimal fair handling for all users of a server, it can be necessary to limit the resources that each user/connection can utilize so as to maximize throughput for the server or to ensure that the entire server runs within the limitations of it&#8217;s runtime.</p>
</div>
<div class="sect3">
<h4 id="_low-resources-monitor"><a class="anchor" href="#_low-resources-monitor"></a><a class="link" href="#_low-resources-monitor">Low Resources Monitor</a></h4>
<div class="paragraph">
<p>An instance of <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/LowResourcesMonitor.html">LowResourcesMonitor</a> may be added to a Jetty server to monitor for low resources situations and to take action to limit the number of idle connections on the server.
To configure the low resources monitor, you can enable the the <code>lowresources.mod</code> on the command line, which has the effect of including the following XML configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml">Unresolved directive in tuning/limit-load.adoc - include::/home/joakim/code/jetty/jetty.project-10.0.x/documentation/jetty-documentation/../jetty-server/src/main/config/etc/jetty-lowresources.xml[]</code></pre>
</div>
</div>
<div class="paragraph">
<p>The monitor is configured with a period in milliseconds at which it will scan the server looking for a low resources condition, which may be one of:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>If <code>monitorThreads</code> is configured as true and a connectors Executor is an instance of <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/util/thread/ThreadPool.html">ThreadPool</a>, then its <code>isLowOnThreads()</code> method is used to detect low resources.</p>
</li>
<li>
<p>If <code>maxConnections</code> is configured to a number &gt;0 then if the total number of connections from all monitored connectors exceeds this value, then low resources state is entered.</p>
</li>
<li>
<p>If the <code>maxMemory</code> field is configured to a number of bytes &gt;0 then if the JVMs total memory minus its idle memory exceeds this value, then low resources state is entered.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Once low resources state is detected, then the monitor will iterate over all existing connections and set their <code>IdleTimeout</code> to its configured <code>lowResourcesIdleTimeout</code> in milliseconds.
This allows the idle time of existing connections to be reduced so that the connection is quickly closed if no further request are received.</p>
</div>
<div class="paragraph">
<p>If the low resources state persists longer than the time in milliseconds configured for the <code>maxLowResourcesTime</code> field, the the <code>lowResourcesIdleTimeout</code> is repeatedly applied so that new connections as well as existing connections will be limited.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="websocket-jetty"><a class="anchor" href="#websocket-jetty"></a><a class="link" href="#websocket-jetty">Jetty Websocket API</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>These pages are works in progress that have not been moved to their respective sections yet.</p>
</div>
<div class="sect2">
<h3 id="websocket-jetty-server-api"><a class="anchor" href="#websocket-jetty-server-api"></a><a class="link" href="#websocket-jetty-server-api">Jetty WebSocket Server API</a></h3>
<div class="paragraph">
<p>Jetty provides the ability to wire up WebSocket endpoints to Servlet Path Specs via the use of a <code>JettyWebSocketServlet</code> bridge servlet.</p>
</div>
<div class="paragraph">
<p>Internally, Jetty manages the HTTP Upgrade to WebSocket and migration from a HTTP Connection to a WebSocket Connection.</p>
</div>
<div class="paragraph">
<p>This will only work when running within the Jetty Container (unlike past Jetty technologies, you cannot get Jetty WebSocket server functionality running Jetty within other containers like JBoss, Tomcat, or WebLogic).</p>
</div>
<div class="sect3">
<h4 id="_the-jetty-websocketservlet"><a class="anchor" href="#_the-jetty-websocketservlet"></a><a class="link" href="#_the-jetty-websocketservlet">The Jetty WebSocketServlet</a></h4>
<div class="paragraph">
<p>To wire up your WebSocket to a specific path via the <code>JettyWebSocketServlet</code>, you will need to extend <code>org.eclipse.jetty.websocket.servlet.JettyWebSocketServlet</code> and specify what <code>WebSocket</code> object should be created with incoming Upgrade requests.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in websockets/jetty/jetty-websocket-server-api.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyEchoServlet.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This example will create a Servlet mapped via the <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/annotation/WebServlet.html">@WebServlet</a> annotation to the Servlet path spec of <code>"/echo"</code> (or you can do this manually in the <code>WEB-INF/web.xml</code> of your web application) which will create MyEchoSocket instances when encountering HTTP Upgrade requests.</p>
</div>
<div class="paragraph">
<p>The <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/websocket/servlet/JettyWebSocketServlet.html#configure(org.eclipse.jetty.websocket.servlet.JettyWebSocketServletFactory)"><code>JettyWebSocketServlet.configure(JettyWebSocketServletFactory factory)</code></a> is where you put your specific configuration for your WebSocket.
In the example we specify a 10 second idle timeout and register MyEchoSocket with the default JettyWebSocketCreator the WebSocket class we want to be created on Upgrade.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
It is important that you take in account any firewall or router timeouts
when configuring websockets. Be sure the websocket configuration is
lower than your firewall or router.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect3">
<h4 id="_using-the-jettywebsocketcreator"><a class="anchor" href="#_using-the-jettywebsocketcreator"></a><a class="link" href="#_using-the-jettywebsocketcreator">Using the JettyWebSocketCreator</a></h4>
<div class="paragraph">
<p>All WebSocket&#8217;s are created via whatever <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/websocket/servlet/JettyWebSocketCreator.html">JettyWebSocketCreator</a> you have registered with the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/websocket/servlet/JettyWebSocketServletFactory.html">JettyWebSocketServletFactory</a>.</p>
</div>
<div class="paragraph">
<p>By default, the <code>JettyWebSocketServletFactory</code> is a simple <code>JettyWebSocketCreator</code> capable of creating a single WebSocket object.
Use <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/websocket/servlet/JettyWebSocketServletFactory.html#register(java.lang.Class)"><code>JettyWebSocketCreator.register(Class&lt;?&gt; websocket)</code></a> to tell the <code>JettyWebSocketServletFactory</code> which class it should instantiate (make sure it has a default constructor).</p>
</div>
<div class="paragraph">
<p>If you have a more complicated creation scenario, you might want to provide your own <code>JettyWebSocketCreator</code> that bases the WebSocket it creates off of information present in the <code>UpgradeRequest</code> object.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in websockets/jetty/jetty-websocket-server-api.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAdvancedEchoCreator.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Here we show a <code>JettyWebSocketCreator</code> that will utilize the <a href="http://tools.ietf.org/html/rfc6455#section-1.9">WebSocket subprotocol</a> information from request to determine what WebSocket type should be
created.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">Unresolved directive in websockets/jetty/jetty-websocket-server-api.adoc - include::/home/joakim/code/jetty/jetty.project-<span class="float">10.0</span>.x/documentation/jetty-documentation/../jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAdvancedEchoServlet.java<span class="type">[]</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>When you want a custom <code>JettyWebSocketCreator</code>, use <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/websocket/servlet/JettyWebSocketServletFactory.html#setCreator(org.eclipse.jetty.websocket.servlet.JettyWebSocketCreator)"><code>JettyWebSocketServletFactory.setCreator(JettyWebSocketCreator creator)</code></a> and the <code>JettyWebSocketServletFactory</code> will use your creator for all incoming Upgrade requests on this servlet.</p>
</div>
<div class="paragraph">
<p>Other uses for a <code>JettyWebSocketCreator</code>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Controlling the selection of WebSocket subprotocol</p>
</li>
<li>
<p>Performing any WebSocket origin you deem important.</p>
</li>
<li>
<p>Obtaining the HTTP headers from incoming request</p>
</li>
<li>
<p>Obtaining the Servlet HttpSession object (if it exists)</p>
</li>
<li>
<p>Specifying a response status code and reason</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>If you don&#8217;t want to accept the upgrade, simply return null from the <a href="https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/websocket/servlet/JettyWebSocketCreator.html#createWebSocket(org.eclipse.jetty.websocket.api.UpgradeRequest,org.eclipse.jetty.websocket.api.UpgradeResponse)"><code>JettyWebSocketCreator.createWebSocket(UpgradeRequest req, UpgradeResponse resp)</code></a> method.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="websocket-java"><a class="anchor" href="#websocket-java"></a><a class="link" href="#websocket-java">Java Websocket API</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>JSR-356 These pages are works in progress that have not been moved to
their respective sections yet.</p>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Version 10.0.10<br>
Last updated 2022-06-16 14:13:48 -0500
</div>
</div>
</body>
</html>