tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Garret Wilson <gar...@globalmentor.com>
Subject Re: Tomcat multiple init(), no init param
Date Mon, 26 Jun 2006 00:39:50 GMT
Garret Wilson wrote:
> It's as if two instances of Tomcat are being run in two separate JVMS: 
> one using the server.xml configuration, and another attempting to 
> deploy the .war files using some default configuration. The first set 
> of initialized servlets continue to run and accept connections. What's 
> wrong here?

I've found the problem. If you remember, my server.xml had this:

<Host name="www.example.com" appBase="/var/web/apps"
 unpackWARs="false" autoDeploy="false"
 xmlValidation="false" xmlNamespaceAware="false">
    <Alias>example.com</Alias>
    <Context path="" docBase="www.example.com.war">
        <Parameter name="dataDirectory" 
value="/var/web/data/www.example.com/"/>
    </Context>
</Host>

Tomcat would deploy my .war file as specified, using the given init 
parameter. But then, because my .war file was in the appBase directory 
(here "/var/web/apps"), Tomcat would going through and deploying the 
.war file a second time even though autoDeploy was set to "false". One 
way to fix this it to change the appBase so that my .war file wasn't in 
the application base directory:

<Host name="www.example.com" appBase="/var/web"
 unpackWARs="false" autoDeploy="false"
 xmlValidation="false" xmlNamespaceAware="false">
    <Alias>example.com</Alias>
    <Context path="" docBase="apps/www.example.com.war">
        <Parameter name="dataDirectory" 
value="/var/web/data/www.example.com/"/>
    </Context>
</Host>

But the easier way is to add deployOnStartup="false" to the host 
configuration, like this:

<Host name="www.example.com" appBase="/var/web/apps"
 unpackWARs="false" autoDeploy="false" deployOnStartup="false"
 xmlValidation="false" xmlNamespaceAware="false">
    <Alias>example.com</Alias>
    <Context path="" docBase="www.example.com.war">
        <Parameter name="dataDirectory" 
value="/var/web/data/www.example.com/"/>
    </Context>
</Host>

Sure enough, there is a small note on this at 
http://tomcat.apache.org/tomcat-5.5-doc/config/host.html#Automatic%20Application%20Deployment

: "When using automatic deployment, the docBase defined by an XML 
Context file should be outside of the appBase directory. If this is not 
the case difficulties may be experienced deploying the web application 
or the application may be deployed twice."

Well, that's why I turned off autoDeploy---but it seems I need to turn 
off deployOnStartup as well.

Garret

>
> Thanks in advance,
>
> Garret
>
> Garret Wilson wrote:
>> Tomcat 5.5.16 seems to call a servlet's init() method several times, 
>> and the specific init parameter is missing in all but the first.
>>
>> I have a simple server.xml that includes:
>>
>> <Host name="www.example.com" appBase="/var/web/apps"
>> unpackWARs="false" autoDeploy="false"
>> xmlValidation="false" xmlNamespaceAware="false">
>>
>>    <Alias>example.com</Alias>
>>
>>    <Context path="" docBase="www.example.com.war">
>>        <Parameter name="dataDirectory" 
>> value="/var/web/data/www.example.com/"/>
>>    </Context>
>>
>> </Host>
>>
>> In www.example.com.war I have a web.xml file that includes two 
>> instances of MyServlet, with servlet names of myServlet1 and 
>> myServlet2, mapped to "/*" and "/example/*", respectively.
>>
>> Tomcat does the following, which I find odd:
>>
>> 1. myServlet1.init() is called. The init parameter "dataDirectory" is 
>> correctly set to "/var/web/data/www.example.com/".
>>
>> 2. catalina.out indicates "Jun 25, 2006 2:07:26 PM 
>> org.apache.catalina.startup.HostConfig deployWAR".
>>
>> 3. myServlet.init is called(). The init parameter "dataDirectory" 
>> returns null.
>>
>> 4. myServlet2.init is called(). The init parameter "dataDirectory" 
>> returns null.
>>
>> (Then steps 3 and 4 are repeated, presumably because steps 2 and 3 
>> throw NullPointerExceptions, which results from the missing init 
>> parameter.)
>>
>> This confuses me:
>>
>> * Why is myServlet1.init() called twice?
>> * Why isn't myServlet2.init() called before the second call to 
>> myServlet1.init()?
>> * Why is the init parameter "dataDirectory" only available in the 
>> first call to myServlet1.init()?
>>
>> Thanks for any insight,
>>
>> Garret
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message