Search code examples
javastruts2classnotfoundexception

Class not found exception in Struts 2


I am using java web development and seem to be having some issue with some classes not being loaded properly. From reading online and from similar problems, they key take away was that one has to be sure to include all the necessary jar files in their right place. I believe that I did that correctly. This is the error that I get when I start Tomcat

java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)

This is my directory structure

enter image description here

This is the content of my 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>ProtienTracker</display-name>
  
 <filter>
     <filter-name>struts2</filter-name>
     <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
 </filter>

 <filter-mapping>
     <filter-name>struts2</filter-name>
     <url-pattern>/*</url-pattern>
 </filter-mapping> 
  
</web-app>

The error message is also vague and was wondering how anybody might go about debugging it. Any insight would be appreciated!


Solution

  • According to the documentation, this package of this class is org.apache.struts2.dispatcher.ng.filter, and not org.apache.struts2.dispatcher.filter.