Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

struts2

I just started learning struts2 when I am trying to deploy to tomcat I am encountering the following error

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

I went through couple of other posts but I am unable to resolve the issue please help me.. Thanks much !

/here is the web.xml file I am using/

<?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>

/console/

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)
like image 694
user3595026 Avatar asked May 02 '14 05:05

user3595026


2 Answers

I figured out my problem was that I forgot to export my user defined libraries, in this case, struts libraries. You can export the libraries via Eclipse by

  1. Go to the Markers tab (If you can't see, do Windows > Show View > Markers)
  2. Expand "Classpath Dependency Validator Message"
  3. Right click "Classpath entry org.eclipse.jdt.USER_LIBRARY/struts2 will not be exported or published. Runtime ClassNotFoundExceptions may result."
  4. Click "Quick Fix"
  5. Select "Mark the associated raw classpath entry as a publish/export dependency."
  6. click "Finish"
like image 142
Mr. 14 Avatar answered Oct 21 '22 02:10

Mr. 14


There could be some reasons to get this error. One of the reason can be the version of jar you use does not have the required class. Check struts2-core-X.X.X.X.jar, and make sure that it contains StrutsPrepareAndExecuteFilter class under org.apache.struts2.dispatcher.ng.filter package.

like image 28
Khaino Avatar answered Oct 21 '22 01:10

Khaino