Version: 9.3.29.v20201019 |

Deployment Architecture
Previous | Chapter 4. Deploying to Jetty Home | Next

##### Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development

## Deployment Architecture

Jetty is built around an extensible Deployment Manager architecture complete with formal LifeCycle for Web Applications going through it.

For Jetty to serve content (static or dynamic), a ContextHandler needs to be configured and added to Jetty in the appropriate location. A pluggable `DeploymentManager` exists to make this process easier. The Jetty distribution contains example `DeploymentManager` configurations to deploy WAR files found in a directory to Jetty, and to deploy Jetty context xml files into Jetty as well.

The `DeploymentManager` 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.

### Application Providers

Before Jetty deploys an application, an AppProvider identifies the App and then provides it to the `DeploymentManager`. The main `AppProvider` with the Jetty distribution is the WebAppProvider.

### Application LifeCycle Graph

The core feature of the `DeploymentManager` is the Application LifeCycle Graph.

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.).

New applications enter this graph at the Undeployed node, and the `java.lang.String DeploymentManager.requestAppGoal(App,String)` method pushes them through the graph.

### LifeCycle Bindings

A set of default `AppLifeCycle.Bindings` defines standard behavior, and handles deploying, starting, stopping, and undeploying applications. If desired, custom `AppLifeCycle.Bindings` can be written and assigned anywhere on the Application LifeCycle graph.

Examples of new `AppLifeCycle.Binding` implementations that can be developed include:

- Validating the incoming application.
- Preventing the deployment of known forbidden applications.
- Submitting the installation to an application auditing service in a corporate environment.
- Distributing the application to other nodes in the cluster or cloud.
- Emailing owner/admin of change of state of the application.

There are four default bindings:

- StandardDeployer — Deploys the ContextHandler into Jetty in the appropriate place.
- StandardStarter — Sets the ContextHandler to started and start accepting incoming requests.
- StandardStopper — Stops the ContextHandler and stops accepting incoming requests.
- StandardUndeployer — Removes the ContextHandler from Jetty.

A fifth, non-standard binding, called DebugBinding, is also available for debugging reasons; it logs the various transitions through the Application LifeCycle.

### Understanding the Default WebAppProvider

The WebAppProvider is used for the deployment of Web Applications packaged as WAR files, expanded as a directory, or declared in a Jetty Deployable Descriptor XML File. It supports hot (re)deployment.

The basic operation of the `WebAppProvider` is to periodically scan a directory for deployables. In the standard Jetty Distribution, this is configured in the `${jetty.home}/etc/jetty-deploy.xml` file.

    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
    <Configure id="Server" class="org.eclipse.jetty.server.Server">

      <Call name="addBean">
        <Arg>
          <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
            <Set name="contexts">
              <Ref refid="Contexts" />
            </Set>
            <Call id="webappprovider" name="addAppProvider">
              <Arg>
                <New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
                  <Set name="monitoredDirName"><Property name="jetty.home" default="." />/webapps</Set>
                  <Set name="defaultsDescriptor"><Property name="jetty.home" default="." />/etc/webdefault.xml</Set>
                  <Set name="scanInterval">1</Set>
                  <Set name="extractWars">true</Set>
                </New>
              </Arg>
            </Call>
          </New>
        </Arg>
      </Call>
    </Configure>

The above configuration will create a `DeploymentManager` tracked as a Server LifeCycle Bean, with the following configuration.

contexts
  A passed in reference to the HandlerContainer into which the discovered webapps are deployed. This is normally a reference that points to the `id="Contexts"` found in the `${jetty.home}/etc/jetty.xml` file, which itself is an instance of `ContextHandlerCollection`.
monitoredDirName

  The file path or URL to the directory to scan for web applications.

      Scanning follows these rules:

  1. A base directory must exist.
  2. Hidden Files (starting with `"."`) are ignored.
  3. Directories with names ending in `".d"` are ignored.
  4. Common CVS directories `"CVS"` and `"CVSROOT"` are ignored.
  5. Any `*.war` files are considered automatic deployables.
  6. Any `*.xml` files are considered context descriptor deployables.
  7. 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 Configuring a Specific Web Application Deployment). Since jetty-9.2.7, if either the WAR file or its corresponding XML file changes, the webapp will be redeployed.
  8. A directory is considered to be deployable.
  9. 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.
  10. 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.
  11. All other directories are subject to automatic deployment.
  12. If automatic deployment is used, and the special filename `root.war/ROOT.war` or directory name `root/ROOT` will result in a deployment to the `"/"` context path.
defaultsDescriptor
  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’s own `/WEB-INF/web.xml` is applied. The `${jetty.home}/etc/webdefault.xml` that comes with the Jetty distribution controls the configuration of the JSP and Default servlets, along with MIME-types and other basic metadata.
scanInterval
  The period in seconds between sweeps of the `monitoredDirName` for changes: new contexts to deploy, changed contexts to redeploy, or removed contexts to undeploy.
extractWars
  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.
parentLoaderPriority
  Parameter is a boolean that selects whether the standard Java parent first delegation is used or the servlet specification webapp classloading priority. The latter is the default.

Previous | Top | Next
Hot Deployment | Home | Quickstart Webapps

See an error or something missing? Contribute to this documentation at Github!(Generated: 2020-10-19)