atom feed2 messages in org.apache.tomcat.usersRe: application context loaded twice
FromSent OnAttachments
Mohan RadhakrishnanDec 29, 2002 8:21 pm 
Craig R. McClanahanDec 30, 2002 10:32 am 
Subject:Re: application context loaded twice
From:Craig R. McClanahan (crai@apache.org)
Date:Dec 30, 2002 10:32:09 am
List:org.apache.tomcat.users

On Mon, 30 Dec 2002, Mohan Radhakrishnan wrote:

Date: Mon, 30 Dec 2002 09:52:15 +0530 From: Mohan Radhakrishnan <Moh@hclcomnet.co.in> Reply-To: Tomcat Users List <tomc@jakarta.apache.org> To: Tomcat Users List <tomc@jakarta.apache.org> Subject: application context loaded twice

Hi, Why would

<Context path="" docBase="x" debug="0">

load my application context twice?

My listener is called twice while the following line

<Context path="name" docBase="x" debug="0">

loads it only once.

What am I missing ? Appreciate help.

Let's think for a moment about how Tomcat auto-deploys applications from the "webapps" subdirectory. Basically, it does the following:

* Scans all the <Context> elements that you've created, and deploys an app under the context path you specified. In the case of your first example, you're creating the "root" webapp for this virtual host from the contents of "$CATALINA_HOME/webapps/x".

* Scans all the directories in "webapps" to see if they contain a web application. If so, they are deployed under a context path derived from the directory name. So, Tomcat sees directory "x" and deploys the *same* webapp under context path "/x".

If you do not want this to happen, you need to either ensure that the directory name matches the context path without the leading slash (use special directory name "ROOT" for the root webapp, since you cannot have a zero-length filename on most OSs), or put your context directory someplace other than "webapps" and use an absolute path for the docBase attribute.

So why didn't your second example load the app twice? Simple -- "name" is not a valid context path because it does not start with a slash, so this <Context> entry was not loaded (although I'll bet there are log messages that would tell you about this).

Craig