Tomcat: using webapp context to override default URL

Discussion in 'Java' started by sugnaboris@gmail.com, Mar 5, 2008.

  1. Guest

    Hope someone can help with a config problem I'm having. Many thanks in
    advance for at least taking a look.

    I'm building a WAR using Netbeans 5.5.1. The WAR takes its name from
    the project root directory, so I end up with MyProjectRoot.war. I drop
    this into the webapps folder under Tomcat 5.5, and it gets expanded
    out into a directory of its own called MyProjectRoot. This has a META-
    INF directory, containing a context.xml file, which has the following
    contents:

    <?xml version="1.0" encoding="UTF-8"?>
    <Context path="/MyURL"/>

    in other words, I want to be able to access the webapp using:

    http://<server>:8080/MyURL

    However, I can only access the webapp at:

    http://<server>:8080/MyProjectRoot

    I've noticed that a new file has been generated in the directory:

    Tomcat 5.5\conf\Catalina\localhost

    This is called MyProjectRoot.xml, and has the following contents:

    <?xml version="1.0" encoding="UTF-8"?>
    <Context path="/MyURL"/>

    At the moment, I can work around by renaming the WAR prior to
    deployment; but this should ideally be configurable.

    Can anyone advise on how I can use the webapp configuration to force
    the URL that I want? I thought the context.xml contents would do that:
    it seems to work OK with the NetBeans bundled Tomcat during
    development - although the webapp then lives outside the Tomcat
    hierarchy.

    Thanks again to all who read this far, and especially to anyone who
    can advise on how to achieve this!

    Ron
    , Mar 5, 2008
    #1
    1. Advertising

  2. The trick is to put just a .xml file under conf/Catalina/localhost/

    Try something like:

    <?xml version="1.0" encoding="UTF-8"?>
    <Context docBase="/export/zfs/marcelo/mypath/MyProjectRoot" path="/
    MyUrl"/>

    and put the exploded app under /export/zfs/marcelo/mypath/
    MyProjectRoot/

    See
    http://tomcat.apache.org/tomcat-6.0-doc/deployer-howto.html

    Hope it helps
    Marcelo Morales, Mar 5, 2008
    #2
    1. Advertising

  3. Guest

    On 5 Mar, 17:41, Marcelo Morales <>
    wrote:
    > The trick is to put just a .xml file under conf/Catalina/localhost/
    >
    > Try something like:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <Context docBase="/export/zfs/marcelo/mypath/MyProjectRoot" path="/
    > MyUrl"/>
    >
    > and put the exploded app under /export/zfs/marcelo/mypath/
    > MyProjectRoot/
    >
    > Seehttp://tomcat.apache.org/tomcat-6.0-doc/deployer-howto.html


    Thanks, Marcelo - I'll give it a go and let you know what happens. I
    see that's for 6.0, but maybe it's the same deal with 5.5. I already
    have an automatically-generated file in that location, named after the
    webapp - is the filename important?

    > Hope it helps


    Don't we all! ;-)
    , Mar 6, 2008
    #3
  4. On Mar 6, 4:32 am, wrote:
    > On 5 Mar, 17:41, Marcelo Morales <>
    > wrote:
    >
    > > The trick is to put just a .xml file under conf/Catalina/localhost/

    >
    > > Try something like:

    >
    > > <?xml version="1.0" encoding="UTF-8"?>
    > > <Context docBase="/export/zfs/marcelo/mypath/MyProjectRoot" path="/
    > > MyUrl"/>

    >
    > > and put the exploded app under /export/zfs/marcelo/mypath/
    > > MyProjectRoot/

    >
    > > Seehttp://tomcat.apache.org/tomcat-6.0-doc/deployer-howto.html

    >
    > Thanks, Marcelo - I'll give it a go and let you know what happens. I
    > see that's for 6.0, but maybe it's the same deal with 5.5. I already
    > have an automatically-generated file in that location, named after the
    > webapp - is the filename important?
    >
    > > Hope it helps

    >
    > Don't we all! ;-)


    AFAICT, the filename is important. It shouldn't be, though. I think I
    remember reading about it on the page which link I already sent you.

    Have fun finding out

    Marcelo Morales
    Marcelo Morales, Mar 6, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    429
    S. Justin Gengo [MCP]
    Feb 10, 2006
  2. Sean Berry
    Replies:
    3
    Views:
    4,551
    Tim Terry
    Dec 19, 2005
  3. prezjt
    Replies:
    1
    Views:
    596
    Tor Iver Wilhelmsen
    Mar 8, 2007
  4. hrh1818
    Replies:
    1
    Views:
    659
    hrh1818
    Feb 14, 2008
  5. Andrew
    Replies:
    7
    Views:
    415
    Andrew
    Jun 28, 2009
Loading...

Share This Page