eclipse Tomcat 加载 Struts 2 失败(启动过滤器 struts2 异常)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4880331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tomcat fails to load Struts 2 (exception starting filter struts2)
提问by Tasyne
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:
我正在使用 Eclipse (Java EE / Helios) IDE、struts2 和 Tomcat 7.0.6。我的 Web 应用程序昨天运行良好,但一些未知的更改已将其杀死,服务器启动但不再正常运行。尝试查看 .jsp 文件时,我收到以下消息:
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:
当我尝试通过 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.call(StandardContext.java:5040)
at org.apache.catalina.core.StandardContext.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.
现在这似乎是我以前制作的所有 struts2 应用程序的问题。重新启动 Eclipse 和/或我的 PC 似乎没有帮助。
Here is a copy of my Web.xml (which is very similar, throughout each project):
这是我的 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>
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.
我已经尝试将我的类路径中的某些 .jars 更新到最新版本(尽管我没想到它会起作用)。有谁知道可能会出什么问题?如果您知道还需要什么,我很乐意提供更多信息。
回答by rodolk
I had to add a path to servlet-api in the apache lib folder. Weird but after that it worked
我必须在 apache lib 文件夹中添加一个到 servlet-api 的路径。奇怪,但在那之后它起作用了
回答by user497087
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.
我已经在 Tomcat/Eclipse 中多次看到这种事情,其中基本类似乎突然消失了。我认为 Eclipse/Tomcat 有时会让自己感到困惑。如果我让服务器在启用自动部署的情况下运行并且我做了很多小的更改,这种情况似乎会更频繁地发生。
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.
发生这种情况时,我关闭了服务器。我在我的项目上运行“clean”,然后在 tomcat 服务器上清理并清理服务器工作目录。当我重新启动服务器时,一切又开始工作。
回答by Haleem
Make sure you have all jars including commons-lang3-x.x
确保您拥有包括 commons-lang3-xx 在内的所有 jar
You can find missing jar by looking the apache logs like:
您可以通过查看 apache 日志来找到丢失的 jar,例如:
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtilsat org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) ... 55 more
引起:java.lang.ClassNotFoundException:org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711) 处的 org.apache.commons.lang3.StringUtils 处 org.apache.catalina.loader.WebappClassLoader.loadClass( WebappClassLoader.java:1556) ... 55 更多
回答by praveenm
At a minimum to run a helloworld kind Struts2 app would require these jars.
运行 helloworld 类的 Struts2 应用程序至少需要这些 jars。
- struts2-core-*.jar
- xwork-core-*.jar
- ognl-*.jar
- commons-logging-*.jar
- commons-io*.jar
- commons-lang*.jar
- commons-fileupload*.jar
- freemarker-*.jar
- javaassist-*.jar
- struts2-core-*.jar
- xwork-core-*.jar
- ognl-*.jar
- 公共日志记录-*.jar
- 公共 io*.jar
- 公共语言*.jar
- 公共文件上传*.jar
- 自由标记-*.jar
- javaassist-*.jar
回答by Steven Benitez
First, try checking the Tomcat server log to see if Tomcat is experiencing some type of fatal error upon start up.
首先,尝试检查 Tomcat 服务器日志以查看 Tomcat 在启动时是否遇到某种类型的致命错误。
The exception indicates that the servlet API JAR cannot be found, however you appear to have the JAR in the correct location.
该异常表明找不到 servlet API JAR,但您似乎在正确的位置拥有 JAR。
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?
您是从 Eclipse 运行应用程序吗?如果是这样,可能 Eclipse 没有正确启动 Tomcat。如果您尝试手动启动 Tomcat 并在没有 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.
由于无论是 Eclipse 启动 Tomcat 还是您手动启动它,行为都是一致的,我们可以排除 Eclipse 作为问题的一部分。
I would try the following:
我会尝试以下方法:
- Try deploying a simple servlet project or even a JSP — it may be helpful to know if anythingruns
- Re-install Tomcat — you mentioned this happened abruptly recently, something may have happened to the Tomcat installation
- 尝试部署一个简单的 servlet 项目,甚至是一个 JSP——了解是否有任何运行可能会有所帮助
- 重新安装Tomcat——你提到最近突然发生了这件事,Tomcat安装可能发生了一些事情