• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat 5 and Tomcat 6 : setting context path for each web app

 
Ranch Hand
Posts: 34
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm new to Tomcat and wondering how to set each application context path without touching any file on server. (because I do not have an access to server. It's just a rent server)

I try googling and found article about putting context.xml in META-INF but it does not work.

Thank you in advance.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
META-INF/context.xml does work. However, it is the baseline context, used in cases where you are simply dumping a WAR into the TOMCAT_HOME/webapps directory.

However, that's what most people do, so, I'm not sure why it doesn't work for you.

You can also control Tomcat's context using the Tomcat manager/admin apps.
 
Pongsakorn Semsuwan
Ranch Hand
Posts: 34
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Tim,

I read the document about this context thing and found this

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

Context elements may be explicitly defined:

- In the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all webapps.

- In the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host.

- In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g. foo#bar.xml for a context path of /foo/bar. The default web application may be defined by using a file called ROOT.xml.

- Only if a context file does not exist for the application in the $CATALINA_BASE/conf/[enginename]/[hostname]/, in an individual file at /META-INF/context.xml inside the application files. If the web application is packaged as a WAR then /META-INF/context.xml will be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer /META-INF/context.xml is placed in the host's appBase.

- Inside a Host element in the main conf/server.xml.



Perhaps the context of my application is already defined in some of server configuration files and will not be rewrote even I specify it in META-INF/context.xml ?
 
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pongsakorn you can just keep xxx.xml in /conf and give path to target. And there is no other file where configuration is kept for your deployment, in that case just dont put your war inside your webapps directory. Everything should work fine.
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couple of things to be aware of when using the externally-applied context.xml file:

1. An external context.xml will override (completely) the META-INF/context.xml file (if there is one).

2. The actual name of an external context.xml file (unlike the one in META-INF) is almost never literally "context.xml". It cannot be, since that would only allow deploying one context (webapp), and directories can only hold 1 copy of a given filename.

3. The actual context name that a webapp will appear under when using an external context.xml will be the name of the context.xml file, and NOT what you defined in the Context element within that file. The context name in the context.xml file is only used when it is an internal (META-INF/context.xml). I'm not very happy about that, but that's how it works. So if you define a $CATALINA_BASE/conf/catalina/localhost/fubar.xml file, the webapp will appear at http://localhost:8080/fubar.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic