异常启动过滤器struts2 java.lang.ClassNotFoundException:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

时间:2014-05-02 05:19:11

标签: struts2

当我尝试部署到tomcat时,我刚开始学习struts2我遇到了以下错误

Exception starting filter struts2
java.lang.ClassNotFoundException:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

我经历了几个其他帖子,但我无法解决问题,请帮帮我.. 非常感谢!

/ 这是我正在使用的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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Struts2Start</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>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

/ struts.xml中 /

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
   <package name="default" extends="struts-default">
    <action name="getTutorial" class="com.javabrains.struts.action.TutorialAction">
      <result name="success">/success.jsp</result>
      <result name="error">/error.jsp</result>
    </action>
   </package>
</struts>

/ 控制台 /

SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException:     org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:656)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1635)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

4 个答案:

答案 0 :(得分:12)

我发现我的问题是我忘记导出我的用户定义库,在本例中是struts库。您可以通过Eclipse

导出库
  1. 转到“标记”标签(如果您看不到,请执行Windows&gt;显示视图&gt;标记)
  2. 展开&#34; Classpath依赖性验证器消息&#34;
  3. 右键单击&#34;不会导出或发布类路径条目org.eclipse.jdt.USER_LIBRARY / struts2。可能会导致运行时ClassNotFoundExceptions。&#34;
  4. 点击&#34;快速修复&#34;
  5. 选择&#34;将关联的原始类路径条目标记为发布/导出依赖项。&#34;
  6. 点击&#34;完成&#34;

答案 1 :(得分:1)

可能有一些原因导致此错误。其中一个原因可能是您使用的jar版本没有所需的类。检查mysql> Explain select count(*) from exportusers where status != 'active' and PREndDate < now() - interval 3 month and DTModified < now() - interval 3 month; +----+-------------+------------+-------+-----------------------------------------------------------------------+--------------------------+---------+------+---------+------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+------------+-------+-----------------------------------------------------------------------+--------------------------+---------+------+---------+------------------------------------+ | 1 | SIMPLE | exportusers | range | index_jobs_on_DTModified,index_jobs_on_PREndDate,index_jobs_on_Status | index_jobs_on_DTModified | 5 | NULL | 2377287 | Using index condition; Using where | +----+-------------+------------+-------+-----------------------------------------------------------------------+--------------------------+---------+------+---------+------------------------------------+ 1 row in set (0.30 sec) ,确保其struts2-core-X.X.X.X.jar包下的StrutsPrepareAndExecuteFilter类。

答案 2 :(得分:0)

使用以下罐子并移除所有其他罐子。

  • 公地文件上传-1.3.jar
  • 公地-IO-2.0.1.jar
  • 公地lang3-3.1.jar
  • 共享记录-1.1.3.jar
  • 的freemarker-2.3.19.jar
  • 了Javassist-3.11.0.GA.jar
  • OGNL-3.0.6.jar
  • struts2的核 - 2.3.15.1.jar
  • XWork的核 - 2.3.15.1.jar

答案 3 :(得分:-1)

我遇到了同样的问题。我能够通过添加一些jar文件来解决它。您必须至少拥有以下jar文件:

  1. 公地文件上传-X.X.X.jar
  2. 公地-IO-X.X.jar
  3. 公地琅X.X.jar
  4. 共享记录-X.X.X.jar
  5. 共享记录-API-X.X.jar
  6. 公地lang3-X.X.jar
  7. freemaker的-X.X.X.jar
  8. 了Javassist-X.X.X.GA.jar
  9. OGNL-X.X.X.jar
  10. struts2的核 - X.X.X.X.jar
  11. XWork的核 - X.X.X.X.jar