File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes context.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "context.xml" Watch "context.xml" New topic


vijaya vinayagam

Joined: Dec 09, 2005
Posts: 21
i'am new to Servlets.

1) What is the actual use of the "context.xml" file under "Meta-Inf" folder?.

2) what is the difference of setting the context under the "Meta-Inf" and in the "server.xml" which is under the conf folder of Tomcat.

3) If we are going to declare context in either of the two places is it is important to do the same in the other place too?

a detailed explanation would help me a lot.

Thanks in advance
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Since these questions are all Tomcat-specific, I've moved this to the Tomcat forum.

[Asking smart questions] [About Bear] [Books by Bear]
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
1 - The context.xml file is used to describe and setup a context.

2 - The use of a context.xml is new to Tomcat 5.x. In previous versions, the context was added to server.xml and required Tomcat to be restarted to take effect. Now, with the context.xml, we can deploy, redeploy and undeploy contexts without restarting Tomcat.

3 - Only add a context to one place, which place depends on the version of Tomcat you're using.
vijaya vinayagam

Joined: Dec 09, 2005
Posts: 21
Hi, Ray Stojonic
thanks for the reply.
When i place the complete project folder directly inside my C:\ and set the context under the "server.xml" and when i start the tomcat i can see my project started by tomcat.

but instead of setting the context in the "server.xml" if i set that in "META-INF/context.xml" and when i start the tomcat i can't see my project running.

i think i'am missing some setting here.

let me know aht should i do.
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
Ah, I should have mentioned this before...

For the context.xml to be properly deployed from META-INF to the Tomcat conf directory, (which also includes renaming the context.xml to <Your Context Name>.xml) the context must be deployed through Tomcat manager, as a .war file (Web Application Archive)

If you want to deploy it yourself by copying the files to the webapps directory, you'll need to do it this way:

- stop Tomcat
- copy your context to CATALINA_HOME/webapps
- copy your context.xml to CATALINA_HOME/conf/Localhost(?)
- I'm not at my development computer at the moment, I forget the full path to the directory, just go to conf and drill down until you see .xml files
- rename your context.xml to <Your Context Name>.xml (this must match what's defined in the context.xml)
- restart Tomcat

Once you've deployed it the first time, you won't need to copy the context.xml every time, only when you've made changes to it.

If you're interested in using a war to deploy, simply zip your context directory, rename it to <Your Context Name>.war then use Tomcat manager to deploy it.
I agree. Here's the link:
subject: context.xml
jQuery in Action, 3rd edition