Jump to: navigation, search

Jetty/Feature/Hot Deployment

{{Jetty Feature | 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 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].


Typically a ContextDeployer is defined in a jetty.xml file:

 <Call name=<span class="code-quote">"addLifeCycle"</span>>
     <New class=<span class="code-quote">"org.mortbay.jetty.deployer.ContextDeployer"</span>>
       <Set name=<span class="code-quote">"contexts"</span>><Ref id=<span class="code-quote">"Contexts"</span>/></Set>
       <Set name=<span class="code-quote">"configurationDir"</span>><SystemProperty name=<span class="code-quote">"jetty.home"</span> <span class="code-keyword">default</span><nowiki>=</nowiki><span class="code-quote">"."</span>/>/contexts</Set>
       <Set name=<span class="code-quote">"scanInterval"</span>>1</Set>

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 descriptors are in [Jetty/Reference/jetty.xml syntax|jetty xml] format and define and configure individual contexts. A minimal example is:

 <?xml version=<span class="code-quote">"1.0"</span>  encoding=<span class="code-quote">"ISO-8859-1"</span>?>
 <!DOCTYPE Configure PUBLIC <span class="code-quote">"-<span class="code-comment">//Mort Bay Consulting//DTD Configure//EN"</span> <span class="code-quote">"http://jetty.mortbay.org/configure.dtd"</span>>
 </span><Configure class=<span class="code-quote">"org.eclipse.jetty.webapp.WebAppContext"</span>>
   <Set name=<span class="code-quote">"contextPath"</span>>/test</Set>
   <Set name=<span class="code-quote">"war"</span>><SystemProperty name=<span class="code-quote">"jetty.home"</span> <span class="code-keyword">default</span><nowiki>=</nowiki><span class="code-quote">"."</span>/>/webapps/test</Set>

This example creates an instance of 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.

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 org.mortbay.jetty.deployer.FileConfigurationManager that reads a properties file and makes available the property values to the ContextDeployer. Here's how you would configure the ContextDeployer:

<Call name="addLifeCycle">
    <New class="org.mortbay.jetty.deployer.ContextDeployer">
      <Set name="contexts">Cite error: Invalid <ref> tag;
invalid names, e.g. too many