Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Tomcat context path via META-INF/context.xml

843841Nov 14 2006 — edited Apr 8 2008
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.

Comments

843841
I think processing from a complex file to a simplier one would be a more efficient way to achieve this issue ( to be two may help, too)
843841
I think you responded to the wrong topic.
843841
Oh, and sorry about the first line of text, I meant:

"Am I incorrectly assuming..."
ramp
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.
843841
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.
ramp
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.
843841
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!
843842
Hello, I'm new here, but I decide to post in this forum because I have a similar problem. I'm using Tomcat 5.5 and I have a problem with context modification.
My application, is deployed in $CATALINA_HOME as the name of Interfaz_BD (a folder).

In this application, I create a file, and I would like to create it in $CATALINA_HOME/Interfaz_BD, but it appears in the the directory $CATALINA_HOME. I think this is a context problem, but I don't know how to resolve it. I get confused, with the files context.xml...because I don't know if I have to modify, $CATALINA_HOME/conf/context.xml, or to create and configure $CATALINA_HOME/webapps/Interfaz_BD/META_INF/configure.xml.

Can you help me?

Thanks!

Mario
1 - 8
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 6 2008
Added on Nov 14 2006
8 comments
1,616 views