Skip to main content

How do I remove the root element of my Jetty webapp url?



I am running a Java webapp (let's call it mywebapp).





Currently I access my page in this webapp by pointing locally to:







http://localhost:9000/mywebapp/mystuff







However, I need to access it using:







http://localhost:9000/mystuff







How can I do this? I've tried messing 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'm using Maven - not sure if that may be making the difference.





Thanks!


Comments

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


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


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

    ReplyDelete
  2. In order to set your context path to "/" you'll want to use a Context deployment.
    Note: empty context path string is discouraged in servlet spec 2.5 and effectively forbidden in servlet spec 3.0.

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

    By default, on the Jetty Distribution, both the WebAppProvider and ContextProvider are enabled. This is important to know later, as it will influence your decisions on where to put the mywebapp.war file.

    See 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

    WebAppProvider's role is to pay attention to 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. In other words ${jetty.home}/webapps/MyApp-2.4.war is deployed into the context "/MyApp-2.4". There is also the special "root.war" reserved word that will deploy into the context "/". While this is the easiest deployment mechanism, it sacrifices control over the deployment specifics.

    ContextProvider's role is to pay attention to the ${jetty.home}/contexts/ directory for any jetty-xml formatted deployable contexts. This deployment mechanism gives you the maximum control over the deployment, the 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 of.
    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.

    What you'll want to do is to is:


    Make sure your ContextProvider based deployments are enabled in the start.ini (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 as that will cause the WebAppProvider to also deploy the same webapp and confusing your deployment.


    Finally, you can see how this is done in the jetty distribution itself, just open the ${jetty.home}/contexts/test.xml and look around. You'll see that it loads the ${jetty.home}/webapps/test.war via the ContextProvider's use of the ${jetty.home}/contexts/test.xml into the "/" context path.

    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 tells me 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.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.