Understanding context.xml in tomcat 6
Asked Answered
A

2

6

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,

Auctioneer answered 2/11, 2009 at 12:35 Comment(3)
I don't understand the question. I think you're missing some explanatory text after the "When I edit the testprojekt.xml to:" part. At least I can tell that the exception message is fairly self explaining. Take it literally.Lasandralasater
Please escape your code samples, so we can see them.Fadeless
Please take a close look at the two testprojekt.xml files. I added a BLAH string into the value of the second one. I would expect, that after I changed the value, that my webapplication would have access to these new values. But I dont even come to this part, because I get an exception after saving. And I really dont understand the exception, or what is wrong in my approach.Auctioneer
B
2

I think this is a bug in Tomcat. I filed a bug report but they claim it works as designed. Tomcat has 3 modes of deployment: Directory, WAR and Context Fragment. In your case, it gets confused when reloading.

Here is the sequence leading to the error,

  1. When you deploy the WAR, the context fragment (META-INF/context.xml) is copied to conf/Catalina/[host] directory.
  2. When you modifies the fragment, it correctly detects the change so redeployment is triggered.
  3. However, it forgets this is a WAR deployment and treats it as Directory deployment. The directory is removed by undelpoy so you get the error.

If you only change the XML in META-INF, everything should work for you.

Brightman answered 2/11, 2009 at 16:25 Comment(0)
S
0

Your question is a tad ambiguous but I'll give it a try.

Delete the textprojekt.xml that you edited, make those same changes in the context.xml for your project, and restart tomcat.

It may be caused by a conflict between the two xml files. Changing the xml file that is created by tomcat does nto change the context.xml file for the webapp. At least it doesn't change on tomcat6.0.18 that I use for dev work.

Hope that's helpful.

Sketchbook answered 2/11, 2009 at 13:23 Comment(1)
Hmm, I put the question as well on the tomcat user mailing list, and it seems that this behaviour is a BUG. issues.apache.org/bugzilla/show_bug.cgi?id=47343 But I am wondering, why will a change in the conf/Catalina/localhost/testprojekt.xml REDEPLOY the webapp? I would have guessed, that it would RELOAD the webapp! Where is the right place to put your DB-Configuration (for example) then? You are going to change that, without having downtime. I guess.Auctioneer

© 2022 - 2024 — McMap. All rights reserved.