Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Jetty/Feature/Hot Deployment"

< Jetty‎ | Feature
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Jetty Feature
 
{{Jetty Feature
 
| introduction =
 
| introduction =
Jetty provides capability to deploy an arbitrary context or web application with Jetty-specific configuration. This capability is implemented via ContextDeployer mechanism.
 
| body =
 
The [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/ContextDeployer.java?root=RT_JETTY&view=markup ContextDeployer] may be used to (hot)deploy an arbitrary Context or Web Application with Jetty specific configuration. To statically deploy only standard web applications at startup, use the [[JETTY/Feature/WebAppDeployer|WebAppDeployer].
 
  
==Overview==
+
{{Jetty Redirect|http://www.eclipse.org/jetty/documentation/current/hot-deployment.html}}
  
Typically a ContextDeployer is defined in a jetty.xml file:
+
Jetty provides capability to deploy an arbitrary context or web application by monitoring a directory for changes. If you add a web application or a context descriptor to the directory, Jetty's Deployment Manager (DM) deploys a new context. If you touch or update a context descriptor, the DM stops, reconfigures, and redeploys its context. If you remove a context, the DM stops it and removes it from the server.
  
<source lang="xml">
+
| body =
<Call name="addLifeCycle">
+
  <Arg>
+
    <New class="org.eclipse.jetty.deployer.ContextDeployer">
+
      <Set name="contexts"><Ref id="Contexts"</Set>
+
      <Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts</Set>
+
      <Set name="scanInterval">1</Set>
+
    </New>
+
  </Arg>
+
</Call>
+
</source>
+
  
The ContextDeployer will scan the '''configurationDir''' directory at intervals of '''scanInterval''' seconds for xml descriptors that define contexts. Any contexts found are deployed to the passed '''contexts''' reference to a HandlerContainer (this is normally an instance of ContextHandlerCollection).
+
The deployment manager is a state-oriented mechanism suitable for developers and embedded users to customize to a variety of use cases.  An example follows of the <tt>jetty.xml</tt> that creates the basic deployment manager, which Jetty then uses to plug in the ContextProvider and the WebAppProvider that back the Hot Deployment mechanism.  This example also provides information about adding another node to the deployment state, in this case a debug binding.  In the Jetty distribution this XML is in the <tt>jetty-deploy.xml</tt> file, which combined with the <tt>jetty-contexts.xml</tt> and <tt>jetty-webapps.xml</tt> files comprise the stock jetty hot deployment mechanism.
  
The deployment descriptors are in [Jetty/Reference/jetty.xml syntax|jetty xml] format and define and configure individual contexts. A minimal example is:
+
<source lang="xml">
 +
<Configure id="Server" class="org.eclipse.jetty.server.Server">
  
<source lang="xml">
+
    <Call name="addBean">
<?xml version="1.0" encoding="ISO-8859-1"?>
+
      <Arg>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
+
        <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
+
          <Set name="contexts">
  <Set name="contextPath">/test</Set>
+
            <Ref id="Contexts" />
  <Set name="war"><SystemProperty name="jetty.home" default<nowiki>=</nowiki>"."/>/webapps/test</Set>
+
          </Set>
</Configure>
+
          <Call name="setContextAttribute">
 +
            <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
 +
            <Arg>.*/jsp-api-[^/]*\.jar$|.*/jsp-[^/]*\.jar$</Arg>
 +
          </Call>
 +
         
 +
         
 +
          <!-- Add a customize step to the deployment lifecycle -->
 +
          <!-- uncomment and replace DebugBinding with your extended AppLifeCycle.Binding class
 +
          <Call name="insertLifeCycleNode">
 +
            <Arg>deployed</Arg>
 +
            <Arg>starting</Arg>
 +
            <Arg>customise</Arg>
 +
          </Call>
 +
          <Call name="addLifeCycleBinding">
 +
            <Arg>
 +
              <New class="org.eclipse.jetty.deploy.bindings.DebugBinding">
 +
                <Arg>customise</Arg>
 +
              </New>
 +
            </Arg>
 +
          </Call>
 +
          -->
 +
         
 +
        </New>
 +
      </Arg>
 +
    </Call>
 +
</Configure>
 
</source>
 
</source>
  
This example creates an instance of [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java?root=RT_JETTY&view=markup WebAppContext] and sets the '''contextPath''' to be "/test" and the '''resourceBase''' to be "$jetty.home/webapps/test". Because the context used is a standard web application context, when started it will inspect the resourceBase for a WEB-INF/web.xml for further configuration.
+
| more =
 
+
See the [[Jetty/Feature/ContextDeployer|Context Provider]] and [[Jetty/Feature/WebAppDeployer|WebApp Provider]] documentation for more information. Previously, Jetty implemented this feature via a ContextDeployer and WebappDeployer, which have both been deprecated.  
The ContextDeployer is added to the server as a LifeCycle. This simply means that the deployer will be started and stopped with the server. Ie when server.start() is called, then start will also be called on the deployer.
+
 
+
===Property value substitution===
+
 
+
The ContextDeployer can automatically do property substitution on the context files that it deploys. You define a ConfigurationManager that manages the properties and pass this into the ContextDeployer. There is currently one implementation of the ConfigurationManager, and that is the <tt>org.mortbay.jetty.deployer.FileConfigurationManager</tt> that reads a properties file and makes available the property values to the ContextDeployer. Here's how you would configure the ContextDeployer:
+
 
+
<div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">
+
 
+
+
<Call name="addLifeCycle">
+
  <Arg>
+
    <New class="org.mortbay.jetty.deployer.ContextDeployer">
+
      <Set name="contexts"><Ref id="Contexts"/></Set>
+
      <Set name="configurationDir"><SystemProperty name="jetty.home" default<nowiki>=</nowiki>"."/>/contexts</Set>
+
      <Set name="scanInterval">1</Set>
+
      <Set name="configurationManager">
+
        <New class="org.mortbay.jetty.deployer.FileConfigurationManager">
+
          <Set name="file"><SystemProperty name="jetty.home" default<nowiki>=</nowiki>"."/>/foo.properties</Set>
+
        </New>
+
      </Set>
+
    </New>
+
  </Arg>
+
</Call>
+
 
+
</div></div>
+
 
+
Here's an example of the contents of the foo.properties file:
+
 
+
<div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">
+
 
+
+
foo = /funkyapp
+
 
+
</div></div>
+
 
+
Here's how you would use this in a context xml file:
+
 
+
<div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">
+
 
+
+
<?xml version="1.0"  encoding="ISO-8859-1"?>
+
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
+
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
+
  <Set name="contextPath"><Property name="foo"/></Set>
+
  <Set name="war"><SystemProperty name="jetty.home" default<nowiki>=</nowiki>"."/>/webapps/test</Set>
+
</Configure>
+
 
+
</div></div>
+
 
+
==Contexts==
+
 
+
Because the class of the context is defined in the Configure clause, any type of [http://jetty.mortbay.org/xref/org/mortbay/jetty/handler/ContextHandler.html ContextHandler] may be deployed with this mechanism, included base [http://jetty.mortbay.org/xref/org/mortbay/jetty/handler/ContextHandler.html ContextHandler]s, servlet [http://jetty.mortbay.org/xref/org/mortbay/jetty/servlet/Context.html Context]s, [http://jetty.mortbay.org/xref/org/mortbay/jetty/webapp/WebAppContext.html WebAppContexts] or any class derived from them.
+
 
+
==Hot deploy==
+
 
+
If the scan interval is non-zero, the configuration directory is scanned at that interval (in seconds) for changes to the deployment descriptors. If a descriptor is added to the directory, the new context will be deployed. If a descriptor is touched/updated then it's context will be stopped, reconfigured and redeployed. If a descriptor is removed, then it's context will be stopped and removed from the server.
+
 
+
If the scan interval is zero, then the directory is only scanned at startup.
+
 
+
==Other things to configure==
+
 
+
This mechanism allows the most of the API available on [http://jetty.mortbay.org/apidocs/org/mortbay/jetty/handler/ContextHandler.html ContextHandler] or its derived classes to be called to configure the web application. Useful things to configure include:
+
  
* setAttribute
+
See also the [[Jetty/Feature/Deployment_Manager|Deployment Manager]] feature reference for detailed conceptual information.
* setClassLoader
+
* setContextPath
+
* setVirtualHosts
+
* addServlet
+
* setConfigurations
+
* setExtraClassPath
+
* setDefaultsDescriptor
+
* setDescriptor
+
* setOverrideDescriptor
+
* setSystemClasses
+
* setServerClasses
+
| category = [[Category:Jetty Feature]]
+
 
}}
 
}}

Latest revision as of 15:01, 23 April 2013



Introduction

Warning2.png
Jetty 7 and Jetty 8 are now EOL (End of Life)




THIS IS NOT THE DOCUMENTATION YOU ARE LOOKING FOR!!!!!






All development and stable releases are being performed with Jetty 9 and Jetty 10.






This wiki is now officially out of date and all content has been moved to the Jetty Documentation Hub






Direct Link to updated documentation: http://www.eclipse.org/jetty/documentation/current/hot-deployment.html


Jetty provides capability to deploy an arbitrary context or web application by monitoring a directory for changes. If you add a web application or a context descriptor to the directory, Jetty's Deployment Manager (DM) deploys a new context. If you touch or update a context descriptor, the DM stops, reconfigures, and redeploys its context. If you remove a context, the DM stops it and removes it from the server.

Feature

The deployment manager is a state-oriented mechanism suitable for developers and embedded users to customize to a variety of use cases. An example follows of the jetty.xml that creates the basic deployment manager, which Jetty then uses to plug in the ContextProvider and the WebAppProvider that back the Hot Deployment mechanism. This example also provides information about adding another node to the deployment state, in this case a debug binding. In the Jetty distribution this XML is in the jetty-deploy.xml file, which combined with the jetty-contexts.xml and jetty-webapps.xml files comprise the stock jetty hot deployment mechanism.

<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 id="Contexts" />
          </Set>
          <Call name="setContextAttribute">
            <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
            <Arg>.*/jsp-api-[^/]*\.jar$|.*/jsp-[^/]*\.jar$</Arg>
          </Call>
 
 
          <!-- Add a customize step to the deployment lifecycle -->
          <!-- uncomment and replace DebugBinding with your extended AppLifeCycle.Binding class 
          <Call name="insertLifeCycleNode">
            <Arg>deployed</Arg>
            <Arg>starting</Arg>
            <Arg>customise</Arg>
          </Call>
          <Call name="addLifeCycleBinding">
            <Arg>
              <New class="org.eclipse.jetty.deploy.bindings.DebugBinding">
                <Arg>customise</Arg>
              </New>
            </Arg>
          </Call>
          -->
 
        </New>
      </Arg>
    </Call>
</Configure>

Additional Resources

See the Context Provider and WebApp Provider documentation for more information. Previously, Jetty implemented this feature via a ContextDeployer and WebappDeployer, which have both been deprecated.

See also the Deployment Manager feature reference for detailed conceptual information.

Back to the top