Skip to main content
Jump to: navigation, search

Jetty/Howto/SetContextPathto /

< Jetty‎ | Howto
Revision as of 17:52, 16 January 2012 by Boulay.intalio.com (Talk | contribs) (New page: <span style="display: none;" id="1326750294995S"> </span> {{Jetty Howto | introduction =To set your context path to / you need to use a Context deployment. {{note|Be aware|Java Se...)

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



Introduction

To set your context path to / you need to use a Context deployment.

Note.png
Be aware
Java Servlet Specification 2.5 discourages an empty context path string, and Java Servlet Specification 3.0 effectively forbids it.


In Jetty 7.x, the AppProviders assigned to the DeploymentManager handle context path assignment.

By default, on the Jetty Distribution, both the WebAppProvider and ContextProvider are enabled. This is important to know because it influences your decisions on where to put themywebapp.war file.

Examine the ${jetty.home}/start.ini file, and you'll see that it contains both the references to etc/jetty-webapps.xml and etc/jetty-contexts.xml.

Using the WebAppProvider

The WebAppProvider's role is to look in the ${jetty.home}/webapps/ directory for any deployable applications (such as *.war), and deploy them onto a context of the same name as the filename. For example, the WebAppProvider deploys ${jetty.home}/webapps/MyApp-2.4.war into the context /MyApp-2.4. There is also the special root.war reserved word that deploys into the context / . While this is the easiest deployment mechanism, it sacrifices control over deployment specifics.

Using the ContextProvider

The ContextProvider's role is to look in the ${jetty.home}/contexts/ directory for any jetty-xml formatted, deployable contexts. This deployment mechanism gives you the maximum control over the deployment, as this XML file can control anything that is ultimately resolved to a org.eclipse.jetty.server.handler.ContextHandler base class, of which WebAppContext (WARs, servlets, etc.) are part. The most common use is to specify a WebAppContext-based XML file, and control things such as what files and directories make up the web application, what temporary directory to use, and even what Context Path to use.

Setting the Context Path with the ContextProvider

Make sure your ContextProvider-based deployments are enabled in the start.ini. That is, make sure that etc/jetty-context.xml is present. Create a ${jetty.home}/contexts/mywebapp.xml that declares the <Set name="contextPath">/</Set> option. If you have the etc/jetty-webapps.xml present in your start.ini, do not put your mywebapp.war in ${jetty.home}/webapps because doing so causes the WebAppProvider to also deploy the same webapp and confuses your deployment. Finally, you can see how the jetty distribution itself does this by examining ${jetty.home}/contexts/test.xml. Jetty loads the ${jetty.home}/webapps/test.war via the ContextProvider's use of the ${jetty.home}/contexts/test.xml into the / context path.

Studying the Logs

Another note, look at the logs.

2012-01-13 13:56:28.779:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/home/joakim/code/jetty/distros/jetty-distribution-7.6.0.RC3/webapps/test.war

That reveals that WebAppContext was

Started on {/, (the root Context Path) Using the temp/work directory file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/ Using the web application specified in /home/joakim/code/jetty/distros/jetty-distribution-7.6.0.RC3/webapps/test.war.

Back to the top