Tomcat context path via META-INF/context.xml
Am incorrectly assuming the use of a context.xml file located withing a war file's META-INF directory for deployment within Tomcat 5.5?
I currently have an extremely simple context.xml file in my war (foo-1.0.war), containing the following:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/foo" />
I was under the impression that when deployed within tomcat, my context path would be set as "/foo". The issue I am having is that the context is still the deployed WAR file's name (/foo-1.0).
I am looking for the easiest path for our operations people to handle deployment. So, I thought I would toss a context.xml file in there (foo-1.0.war#/META-INF/context.xml) and call it a day. I see that the file actually gets extracted and placed into the ${catalina.home}/conf/Catalina/localhost directory, with the name "foo-1.0.xml" (which is where I can see how Tomcat is getting the context name).The contents of the file are exactly what is in the original context.xml file.
So, am I missing a step? Is there another configuration I need to set up to get these context files to be able to declare the context path (wow, that is a lot of "to")?
Thanks,
Briggs.
[1231 byte] By [
briggsa] at [2007-10-3 9:49:22]

The general rule is that the value of the path attribute in
<Context path = "........" />
should match with the context name which in turn should match with the name of the context file. The only exception for this that I have seen is when you configire the default context "/" - that context xml goes by the name "ROOT".
This is consistent with the fact that in absence of a context xml file for an exploded directory web application, the context name would be the root directory of the application under the webapps folder.
Hope that helps some.
ram.
Hey Ram, thanks for the reply.
After re-reading the tomcat docs regarding the "path" attribute:
"The context path of this web application, which is matched against the beginning of each request URI to select the appropriate web application for processing. All of the context paths within a particular Host must be unique. If you specify a context path of an empty string (""), you are defining the default web application for this Host, which will process all requests not assigned to other Contexts. The value of this field must not be set except when statically defining a Context in server.xml, as it will be infered from the filenames used for either the .xml context file or the docBase".
.....
I believe it means that if I want to set a context path within the context file, I need to have it defined within the server.xml file also (fyi, I do have a bunch of resources defined within this context .xml file).So, I can either have them rename the war file, or declare a matching context name within the server.xml config file. I would think this is the only way if I want a context that is not directly off the root of the servlet container such as "myserver/some_path/foo_context" otherwidse, relying just on the war name, would cause the deployed context to always be "myserver/foo_context". But that is another issue for another day.
Anyway, I do believe that I assumed incorrectly and that you cannot set the context path by setting only the PATH attribute in the context.xml file.
Boo hoo.
Briggs.
Tweaking server.xml binds your application to that server instance. Install a new version and you have to go in and tweak the files again. Compare this with just dropping your application and context.xml in appropriate locations.
I am sorry if I dint make it clear in my earlier post. All you have to do is speicfy in the path attribute, the name you want for your context file and rename the context file to the chosen context name.
Thus for a context path of say 'foo', I would have my context xml named as foo.xml and it would be as below
<Context path = "/foo" .........../>
ram.
Oh, I am not going to edit the server.xml file. That is exactly what I was avoiding. I was just clearing up what the docs said. I was just trying to find the simplest solution for the operations people, and editing that file isn't it. I've recently moved from a large enterprise environment and application servers to a small company with Servlet containers. So, things are a bit different here. They need explicit instructions on how to deploy this application as they no nothing about Tomcat.I'm busy coding; no time for deployment docs! :-)
So, they can either change the name of the war file and hot deploy, or they can have a specific application-name-context-file.xml for deployment.
I'll let them decide.
Thanks again!