Skip to main content
Jump to: navigation, search

Difference between revisions of "Jetty/Howto/SetContextPathto /"

< Jetty‎ | Howto
m (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...)
 
m
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
  
 
{{Jetty Howto
 
{{Jetty Howto
| introduction =To set your context path to / you need to use a Context deployment.  
+
| introduction =To set your context path to / (the root context path), you need to use a Context deployment.  
  
 
{{note|Be aware|Java Servlet Specification 2.5 discourages an empty context path string, and Java Servlet Specification 3.0 effectively forbids it.}}
 
{{note|Be aware|Java Servlet Specification 2.5 discourages an empty context path string, and Java Servlet Specification 3.0 effectively forbids it.}}
Line 8: Line 8:
 
In Jetty 7.x, the AppProviders assigned to the DeploymentManager handle context path assignment.
 
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 the<tt>mywebapp.war</tt> file.
+
By default on the Jetty Distribution, both the WebAppProvider and ContextProvider are enabled. This is important to know because it influences your decision on where to put the <tt>mywebapp.war</tt> file.
  
Examine the <tt>${jetty.home}/start.ini</tt> file, and you'll see that it contains both the references to <tt>etc/jetty-webapps.xml</tt> and <tt>etc/jetty-contexts.xml</tt>.
+
Examine the <tt>${jetty.home}/start.ini</tt> file, and you'll see that it contains both references to <tt>etc/jetty-webapps.xml</tt> and <tt>etc/jetty-contexts.xml</tt>.
  
 
===Using the WebAppProvider===
 
===Using the WebAppProvider===
Line 22: Line 22:
 
====Setting the Context Path with the ContextProvider====
 
====Setting the Context Path with the ContextProvider====
  
Make sure your ContextProvider-based deployments are enabled in the <tt>start.ini</tt>. That is, make sure that <tt>etc/jetty-context.xml</tt> is present.
+
To set the context path to / , follow these steps.
Create a <tt>${jetty.home}/contexts/mywebapp.xml</tt> that declares the <Set name="contextPath">/</Set> option.
+
#Make sure your ContextProvider-based deployments are enabled in the <tt>start.ini</tt>. That is, make sure that <tt>etc/jetty-context.xml</tt> is present.
If you have the <tt>etc/jetty-webapps.xml</tt> present in your <tt>start.ini</tt>, do not put your <tt>mywebapp.war</tt> in <tt>${jetty.home}/webapps</tt> because doing so causes the WebAppProvider to also deploy the same webapp and confuses your deployment.
+
#Create a <tt>${jetty.home}/contexts/mywebapp.xml</tt> that declares the <tt><Set name="contextPath">/</Set></tt> option.
Finally, you can see how the jetty distribution itself does this by examining <tt>${jetty.home}/contexts/test.xml</tt>. Jetty loads the <tt>${jetty.home}/webapps/test.war</tt> via the ContextProvider's use of the <tt>${jetty.home}/contexts/test.xml</tt> into the / context path.
+
#If you have the <tt>etc/jetty-webapps.xml</tt> present in your <tt>start.ini</tt>, do not put your <tt>mywebapp.war</tt> in <tt>${jetty.home}/webapps</tt> 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 <tt>${jetty.home}/contexts/test.xml</tt>. Jetty loads the <tt>${jetty.home}/webapps/test.war</tt> via the ContextProvider's use of the <tt>${jetty.home}/contexts/test.xml</tt> into the / context path.
  
 
===Studying the Logs===
 
===Studying the Logs===
  
Another note, look at the logs.
+
Look at the logs:
  
 
<tt>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</tt>
 
<tt>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</tt>
Line 35: Line 36:
 
That reveals that WebAppContext was
 
That reveals that WebAppContext was
  
Started on {/, (the root Context Path)
+
*Started on {/, (the root Context Path)
Using the temp/work directory file:<tt>/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/</tt>
+
*It was using the temp/work directory file:<tt>/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/</tt>
Using the web application specified in <tt>/home/joakim/code/jetty/distros/jetty-distribution-7.6.0.RC3/webapps/test.war</tt>.
+
*It was using the web application specified in <tt>/home/joakim/code/jetty/distros/jetty-distribution-7.6.0.RC3/webapps/test.war</tt>.
 
}}
 
}}

Latest revision as of 17:44, 17 January 2012



Introduction

To set your context path to / (the root context path), 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 decision on where to put the mywebapp.war file.

Examine the ${jetty.home}/start.ini file, and you'll see that it contains both 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

To set the context path to / , follow these steps.

  1. Make sure your ContextProvider-based deployments are enabled in the start.ini. That is, make sure that etc/jetty-context.xml is present.
  2. Create a ${jetty.home}/contexts/mywebapp.xml that declares the <Set name="contextPath">/</Set> option.
  3. 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.
  4. 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

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)
  • It was using the temp/work directory file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/
  • It was using the web application specified in /home/joakim/code/jetty/distros/jetty-distribution-7.6.0.RC3/webapps/test.war.

Back to the top