【发布时间】:2014-07-09 12:15:51
【问题描述】:
我使用 Eclipse WTP Tomcat 创建了一个名为“test”的动态 Web 项目,Eclipse 版本是 Java EE Kepler Service Release 2,Tomcat 版本是 7.0.53,Servlet 3.0,Win 8.1 x86,jdk 1.6.0_45,但之后尝试了几次,我发现匹配以下所有条件时会出现问题:
- Webapp(Web 上下文)不在
/webapps(这是 appBase 的默认值)中,并且: - 通过在
\conf\server.xml 中的 元素下写入 元素来配置 Webapp。
这里是
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
<Context docBase="D:/tmpdev/apache-tomcat-7.0.53/wtpwebapps/test" path="/test" reloadable="true"/>
</Host>
这里是“test”的目录结构:
test
├─META-INF
│ MANIFEST.MF
│
└─WEB-INF
│ web.xml
│
├─classes
│ └─test
│ HelloServlet.class
│ MyFilter1.class
│ MyFilter2.class
│ MyHttpSessionListener.class
│ MyServletContextListener.class
│
└─lib
虽然WEB-INF/web.xml默认是
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF\web.xml</WatchedResource>
<WatchedResource>D:/tmpdev/apache-tomcat-7.0.53/wtpwebapps/test/WEB-INF/web.xml</WatchedResource>
<WatchedResource>D:\tmpdev\apache-tomcat-7.0.53\wtpwebapps\test\WEB-INF\web.xml</WatchedResource>
这里是其他有效的配置方式:
- 使用单独的文件
\conf\Catalina\localhost\test.xml 来配置上下文,或者: - 将“test”移动到
\webapps 而不进行任何配置,或者: - 选中 Eclipse WTP 中服务器选项的“服务模块而不发布”
【问题讨论】:
-
你在哪里添加了那些
元素? -
@MarkThomas ,我在 conf/server.xml 中的
元素下一一尝试了那些 元素,但没有人起作用! -
你在每次更改 server.xml 后都重新启动了 Tomcat?
-
@MarkThomas ,是的,我确实重新启动了。我知道如果不重新启动 Tomcat,就无法重新加载主 conf/server.xml 文件。我会检查在Linux下是否会出现这个问题。
-
@MarkThomas ,我在 Ubuntu 下使用相同的 Tomcat 版本进行了测试,它的行为与 Windows 下的行为相同。我还用 Tomcat 7.0.8 再次测试,也没有工作。这似乎是一个错误?
标签: java eclipse tomcat web.xml eclipse-wtp