How to remove the root element of my Jetty webapp url?

I am running Java webapp (let me have it mywebapp).

I am currently accessing my page in this webapp, locally pointing to:

http://localhost:9000/mywebapp/mystuff 

However, I need to access it using:

 http://localhost:9000/mystuff 

How can i do this? I tried messing around with some confs, but to no avail ...

This is my current root.xml:

 <?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">/root</Set> <Set name="war"> <SystemProperty name="app.webapps.path"/>/mywebapp.war </Set> </Configure> 

Also tried:

 <?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">/</Set> <Set name="war"> <SystemProperty name="app.webapps.path"/>/mywebapp.war </Set> </Configure> 

I use Maven - not sure if this can make a difference.

Thanks!

+4
source share
2 answers

To set your path to "/" , you need to use context deployment. Note. You MUST specify a context path string for the purpose of matching path specifications. The empty context path string "" is only valid as a result of matching from queries to the context root. See Section 12.2 of the Servlet Specification)

In Jetty 7.x, the context path assignment is handled by the AppProviders assigned to the DeploymentManager.

The default distribution is Jetty, and WebAppProvider and ContextProvider are included. This is important to know later, as this will affect your decisions about where to put the mywebapp.war file.

See the file ${jetty.home}/start.ini and you will see that it contains links to etc/jetty-webapps.xml and etc/jetty-contexts.xml

The role of WebAppProvider is to pay attention to the ${jetty.home}/webapps/ for any deployed applications (for example, * .war) and deploy them in a context with the same name as the file name. In other words, ${jetty.home}/webapps/MyApp-2.4.war deployed in the context of "/MyApp-2.4" . There is also a special reserved word "root.war" which will be expanded in the context of "/" . Although this is the easiest deployment mechanism, it sacrifices control over deployment features.

The role of ContextProvider is to pay attention to the ${jetty.home}/contexts/ directory for any deployable contexts created in the jetty-xml style. This deployment mechanism gives you maximum control over the deployment, the xml file can manage everything that the org.eclipse.jetty.server.handler.ContextHandler base class is ultimately allowed to use, of which WebAppContext (wars / servlets / etc) are part of. The most common use is to specify an XML file based on the WebAppContext and manage things like the files and directories that make up the web application, which temporary directory to use, and even which context path to use.

What you want to do is:

  • Make sure ContextProvider-based deployments are included in start.ini (make sure etc/jetty-context.xml present)
  • Create ${jetty.home}/contexts/mywebapp.xml that will declare the <Set name="contextPath">/</Set> option.
  • If you have etc/jetty-webapps.xml present in your start.ini, do not put mywebapp.war in ${jetty.home}/webapps , as this will cause WebAppProvider to also deploy the same webapp and confuse your deployment.

Finally, you can see how this is done at the pier itself , just open ${jetty.home}/contexts/test.xml and look ${jetty.home}/contexts/test.xml . You will see that it loads ${jetty.home}/webapps/test.war by using ContextProvider ${jetty.home}/contexts/test.xml in the context path "/" .

One more note: look at the magazines.

2012-01-13 13: 56: 28.779: INFO: oejsh.ContextHandler: started by oejwWebAppContext {/, file: /tmp/jetty-0.0.0.0-8080-test.war -_- any- / webapp /} / home / Joachim / code / marina / distributions / berth-distribution-7.6.0.RC3 / WebApps / test.war

This tells me that WebAppContext was

  • Starts with {/, (root context path)
  • Using the temp / work file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/ 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 .

Update: clarifying the empty path statement.

+4
source

See http://wiki.eclipse.org/Jetty/Howto/Deploy_Web_Applications :

If the webapp is called root.war or the directory is root / then Jetty deploys it in / context.

PS: I never used Jetty, and it took me 3 seconds to find with Google.

+2
source

Source: https://habr.com/ru/post/1390868/


All Articles