You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Carsten Pohl <po...@tyntec.com> on 2009/11/02 13:46:47 UTC

Understanding context.xml

Hi!

I created a mainly empty dynamic web project in eclipse.

It has

- no servlets
- no jsp files

The web.xml is 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>testprojekt</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

and I added a context.xml to its META-INF folder

<?xml version="1.0" encoding="UTF-8"?>
<Context>
        <Parameter name="companyName" value="My Company, Incorporated"  override="false"/>
</Context>

I exported this project as a WAR file. With the following structure:

user@system:$ tree
.
|-- META-INF
|   |-- MANIFEST.MF
|   `-- context.xml
`-- WEB-INF
    |-- classes
    |-- lib
    `-- web.xml

4 directories, 3 files

When I deploy the project to a local tomcat (Apache Tomcat/6.0.20) Everything works as expected. Meaning, the context.xml is copied to /conf/Catalina/localhost and renamed to testprojekt.xml.

When I edit the testprojekt.xml to:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
  <Parameter name="companyName" value="My BLAH Company, Incorporated"  override="false"/>
</Context>

I see the following output in the catalina.out:

02.11.2009 13:21:35 org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/testprojekt]
02.11.2009 13:21:35 org.apache.catalina.core.StandardContext resourcesStart
SCHWERWIEGEND: Error starting static Resources
java.lang.IllegalArgumentException: Document base /opt/tomcat6/webapps/testprojekt does not exist or is not a readable directory
        at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:142)
        at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4048)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4217)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
        at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:556)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1274)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:296)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
        at java.lang.Thread.run(Thread.java:619)
02.11.2009 13:21:35 org.apache.catalina.core.StandardContext start
SCHWERWIEGEND: Error in resourceStart()
02.11.2009 13:21:35 org.apache.catalina.core.StandardContext start
SCHWERWIEGEND: Error getConfigured
02.11.2009 13:21:35 org.apache.catalina.core.StandardContext start
SCHWERWIEGEND: Context [/testprojekt] startup failed due to previous errors
02.11.2009 13:21:35 org.apache.catalina.core.StandardContext stop
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/testprojekt] has not been started

Why is that? Is that the expected result? What is the right way to change parameters in a context.xml?

Thank you in advance.
Regards,
Carsten Pohl

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


Re: Understanding context.xml

Posted by Markus Schönhaber <to...@list-post.mks-mail.de>.
Carsten Pohl:

> If I change the testprojekt.xml in
> conf/Catalina/localhost/testprojekt.xml my webapplication will be
> redeployed (assuming the bug is fixed), and it would get the new
> values. If I change the conf/context.xml all my webapps will be
> RELOADED, but new values and changes to values in conf/context.xml
> will not be given to the webapp.

Hm, indeed.
If the changes in conf/context.xml aren't propagated to the webapps, I
don't see the point in reloading the apps on changes in that file.
But I don't know if this is a (known) bug or if it works as designed and
I'm simply misunderstanding how it's supposed to work.

> I am using the tomcat connection pooling to connect to a postgres DB,
> I would like to put the configuration (hostname, username, etc)
> somewhere, so that i can change it, when I change the databasehost.
> Where is the right place to put such a configuration?
> 
> If i put the configuration in conf/context.xml the changes to the
> values wont be given to running applications.
> 
> If i put it in the conf/Catalina/.... the application will be
> redeployed, which causes downtimes.
> 
> What is the right place to PUT and later change the connection infos
> to the database?

Well what is right for you depends on your needs.
I configure <Resource> elements in the webapp's context.xml - but YMMV.

Anyway: I don't know of a built-in method that would enable a webapp to
see changes in a <Resource> configuration without a reload of the app.
But maybe someone else can provide better/additional information.

-- 
Regards
  mks

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


Re: Understanding context.xml

Posted by Carsten Pohl <po...@tyntec.com>.
Oh, Thanks a lot, I would have never guessed that it is a bug in tomcat. But I would like to ask a follow up question.

If I change the testprojekt.xml in conf/Catalina/localhost/testprojekt.xml my webapplication will be redeployed (assuming the bug is fixed), and it would get the new values. If I change the conf/context.xml all my webapps will be RELOADED, but new values and changes to values in conf/context.xml will not be given to the webapp.

I am using the tomcat connection pooling to connect to a postgres DB, I would like to put the configuration (hostname, username, etc) somewhere, so that i can change it, when I change the databasehost. Where is the right place to put such a configuration?

If i put the configuration in conf/context.xml the changes to the values wont be given to running applications.

If i put it in the conf/Catalina/.... the application will be redeployed, which causes downtimes.

What is the right place to PUT and later change the connection infos to the database?

Thank you again for your help.
Regards,
Carsten Pohl


----- Original Message -----
From: "Markus Schönhaber" <to...@list-post.mks-mail.de>
To: users@tomcat.apache.org
Sent: Monday, 2 November, 2009 13:53:15 GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: Re: Understanding context.xml

Carsten Pohl:

> When I deploy the project to a local tomcat (Apache Tomcat/6.0.20) Everything works as expected. Meaning, the context.xml is copied to /conf/Catalina/localhost and renamed to testprojekt.xml.
> 
> When I edit the testprojekt.xml to:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Context>
>   <Parameter name="companyName" value="My BLAH Company, Incorporated"  override="false"/>
> </Context>
> 
> I see the following output in the catalina.out:
> 
> 02.11.2009 13:21:35 org.apache.catalina.startup.HostConfig checkResources
> INFO: Undeploying context [/testprojekt]
> 02.11.2009 13:21:35 org.apache.catalina.core.StandardContext resourcesStart
> SCHWERWIEGEND: Error starting static Resources
> java.lang.IllegalArgumentException: Document base /opt/tomcat6/webapps/testprojekt does not exist or is not a readable directory
[...]
> INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/testprojekt] has not been started
> 
> Why is that? Is that the expected result? What is the right way to change parameters in a context.xml?

You might be affected by this bug:
https://issues.apache.org/bugzilla/show_bug.cgi?id=47343

-- 
Regards
  mks

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


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


Re: Understanding context.xml

Posted by Markus Schönhaber <to...@list-post.mks-mail.de>.
Carsten Pohl:

> When I deploy the project to a local tomcat (Apache Tomcat/6.0.20) Everything works as expected. Meaning, the context.xml is copied to /conf/Catalina/localhost and renamed to testprojekt.xml.
> 
> When I edit the testprojekt.xml to:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Context>
>   <Parameter name="companyName" value="My BLAH Company, Incorporated"  override="false"/>
> </Context>
> 
> I see the following output in the catalina.out:
> 
> 02.11.2009 13:21:35 org.apache.catalina.startup.HostConfig checkResources
> INFO: Undeploying context [/testprojekt]
> 02.11.2009 13:21:35 org.apache.catalina.core.StandardContext resourcesStart
> SCHWERWIEGEND: Error starting static Resources
> java.lang.IllegalArgumentException: Document base /opt/tomcat6/webapps/testprojekt does not exist or is not a readable directory
[...]
> INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/testprojekt] has not been started
> 
> Why is that? Is that the expected result? What is the right way to change parameters in a context.xml?

You might be affected by this bug:
https://issues.apache.org/bugzilla/show_bug.cgi?id=47343

-- 
Regards
  mks

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