Tomcat无法加载Struts 2(启动过滤器struts2异常)
我正在使用 Eclipse (Java EE / Helios) IDE、struts2 和 Tomcat 7.0.6。我的 Web 应用程序昨天工作正常,但一些未知的更改杀死了它,服务器启动但不再正常运行。当尝试查看 .jsp 文件时,我收到以下消息:
描述请求的资源() 不可用。
(如果它甚至决定提出该错误)
当我尝试通过 Eclipse 启动 Tomcat 服务器并加载“Add.jsp”页面时,在控制台中查看会出现此错误:
...
INFO: Starting service Catalina
Feb 2, 2011 1:38:08 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.6
Feb 2, 2011 1:38:08 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.NoClassDefFoundError: javax/servlet/Filter
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1488)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:252)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4382)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5040)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5035)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Feb 2, 2011 1:38:08 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error filterStart
Feb 2, 2011 1:38:08 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/StrutsTest] startup failed due to previous errors
Feb 2, 2011 1:38:09 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.NoClassDefFoundError: javax/servlet/Filter
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
...
这现在看来是一个问题我之前制作的所有 struts2 应用程序。重新启动 Eclipse 和/或我的电脑似乎没有帮助。
这是我的 Web.xml 的副本(在每个项目中都非常相似):
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Development Environments</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>Add.jsp</welcome-file>
</welcome-file-list>
</web-app>
我尝试将类路径中的某些 .jar 更新到最新版本(尽管我没想到会起作用)。有谁知道可能出了什么问题?如果您知道还需要什么,我很乐意提供更多信息。
I am using the Eclipse (Java EE / Helios) IDE, struts2, and Tomcat 7.0.6. My web application was working fine yesterday, but some unknown change has killed it and the server starts but no longer functions correctly. When trying to view a .jsp file, I am greeted with the message:
description The requested resource ()
is not available.
(if it even decides to put up that error at all)
A look in the console gives me this error when I try to start the Tomcat server via Eclipse and load the 'Add.jsp' page:
...
INFO: Starting service Catalina
Feb 2, 2011 1:38:08 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.6
Feb 2, 2011 1:38:08 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.NoClassDefFoundError: javax/servlet/Filter
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1488)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:252)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4382)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5040)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5035)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Feb 2, 2011 1:38:08 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error filterStart
Feb 2, 2011 1:38:08 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/StrutsTest] startup failed due to previous errors
Feb 2, 2011 1:38:09 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.NoClassDefFoundError: javax/servlet/Filter
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
...
This appears to now be a problem with all of the struts2 applications I have made previously. Restarting Eclipse and/or my PC doesn't seem to help.
Here is a copy of my Web.xml (which is very similar, throughout each project):
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Development Environments</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>Add.jsp</welcome-file>
</welcome-file-list>
</web-app>
I've tried updating certain .jars in my classpath to the latest version (although I didn't expect that to work). Does anyone know what might be going wrong? I'm happy to give more information if you know what else is needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我必须在 apache lib 文件夹中添加 servlet-api 的路径。奇怪,但之后它起作用了
I had to add a path to servlet-api in the apache lib folder. Weird but after that it worked
我在 Tomcat/Eclipse 中多次看到过这种情况,其中基本类似乎突然消失了。我认为 Eclipse/Tomcat 有时会让自己感到困惑。如果我让服务器在启用自动部署的情况下运行并且我做了很多小的更改,那么这种情况似乎会更频繁地发生。
当这种情况发生时,我关闭了服务器。我在我的项目上运行“clean”,然后在 tomcat 服务器上进行清理并清理服务器工作目录。当我重新启动服务器时,一切又开始工作。
I've seen this sort of thing several times with Tomcat/Eclipse where basic classes suddenly seem to disappear. I think that Eclipse/Tomcat just get themselves confused at times. It seems to happen more often if I've left the server running with auto-deploy enabled and I make a lot of small changes.
When this happens I shut down the server. I run "clean" on my project and then clean on the tomcat server and clean the server work directory. When I restart the server everything starts working again.
首先,尝试检查 Tomcat 服务器日志,看看 Tomcat 在启动时是否遇到某种类型的致命错误。
该异常表明无法找到 servlet API JAR,但该 JAR 似乎位于正确的位置。
您是否从 Eclipse 运行该应用程序?如果是这样,也许 Eclipse 没有正确启动 Tomcat。如果您尝试手动启动 Tomcat 并在没有 Eclipse 的情况下部署应用程序,会发生什么情况?
更新
由于无论 Eclipse 启动 Tomcat 还是手动启动 Tomcat,行为都是一致的,因此我们可以排除 Eclipse 是问题的一部分。
我会尝试以下操作:
First, try checking the Tomcat server log to see if Tomcat is experiencing some type of fatal error upon start up.
The exception indicates that the servlet API JAR cannot be found, however you appear to have the JAR in the correct location.
Are you running the application from Eclipse? If so, perhaps Eclipse is not starting Tomcat properly. What happens if you try to start Tomcat manually and deploy your application without Eclipse?
Update
Since the behavior was consistent whether Eclipse started Tomcat or you started it manually, we can rule out Eclipse as part of the problem.
I would try the following:
确保您拥有包括 commons-lang3-xx 在内的所有 jar
您可以通过查看 apache 日志来找到丢失的 jar,如下所示:
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
在 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
在 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
... 55 更多
Make sure you have all jars including commons-lang3-x.x
You can find missing jar by looking the apache logs like:
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
... 55 more
运行 helloworld 类型的 Struts2 应用程序至少需要这些 jar。
At a minimum to run a helloworld kind Struts2 app would require these jars.