This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Tomcat 5 and Tomcat 6 : setting context path for each web app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat 5 and Tomcat 6 : setting context path for each web app" Watch "Tomcat 5 and Tomcat 6 : setting context path for each web app" New topic
Author

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

Pongsakorn Semsuwan
Ranch Hand

Joined: May 15, 2011
Posts: 34

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.


A web application developer wannabe from Thailand
My StartUp : http://www.dreamlog.co
Blog : http://pongsakornsemsuwan.wordpress.com
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Pongsakorn Semsuwan
Ranch Hand

Joined: May 15, 2011
Posts: 34

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 ?
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

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

Joined: Jun 25, 2001
Posts: 16101
    
  21

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.
 
 
subject: Tomcat 5 and Tomcat 6 : setting context path for each web app