了解tomcat 6中的context.xml [英] Understanding context.xml in tomcat 6
问题描述
我在eclipse中创建了一个主要空的动态Web项目。
I created a mainly empty dynamic web project in eclipse.
它有
- 没有servlets
- 没有jsp文件
web.xml是
<?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>
我添加了 context.xml
到其 META-INF
文件夹
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Parameter name="companyName" value="My Company, Incorporated" override="false"/>
</Context>
我将此项目导出为WAR文件。具有以下结构:
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
当我将项目部署到本地tomcat时(Apache Tomcat / 6.0.20) )一切都按预期工作。这意味着,context.xml被复制到/ conf / Catalina / localhost并重命名为testprojekt.xml。
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.
当我将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>
我在catalina.out中看到以下输出:
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
为什么?这是预期的结果吗?更改 context.xml
中参数的正确方法是什么?
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,
推荐答案
我认为这是Tomcat中的一个错误。我提交了一份错误报告,但他们声称它按设计工作。 Tomcat有3种部署模式:Directory,WAR和Context Fragment。在你的情况下,它在重新加载时会感到困惑。
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.
这是导致错误的序列,
- 部署WAR时,上下文片段(META-INF / context.xml)将复制到conf / Catalina / [host]目录。
- 修改时片段,它正确地检测到更改,因此触发了重新部署。
- 但是,它会忘记这是一个WAR部署并将其视为目录部署。该目录被取消删除,因此您收到错误。
如果您只更改META-INF中的XML,一切都应该适用于你。
If you only change the XML in META-INF, everything should work for you.
这篇关于了解tomcat 6中的context.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!