java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter in web.xml [duplicate]
Asked Answered
A

8

8

This is my web.xml Code,While running I am getting error like this..How to resolve this?

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

 <?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" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    id="WebApp_ID" version="2.5">
      <display-name>HelloStruts</display-name>


      <filter>
      <filter-name>Struts</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      </filter>

      <filter-mapping>
      <filter-name>Struts</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>

      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
Analog answered 27/1, 2015 at 10:6 Comment(2)
The classpath requires Struts 2 core packages.Mycetozoan
Which version of S2?Imminent
S
43

if you are using struts2 version 2.5 you need to change from:

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

to:

org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter

Version Notes 2.5

Styracaceous answered 30/6, 2016 at 17:4 Comment(1)
The time when question had been asked here there was not Struts version 2.5 released.Mycetozoan
F
0

This will occur because the correct version of the struts2-core.jar is not on the lib path. Please check your lib directory and ensure that you have the right version of struts2-core.jar.

If you have the jar in your lib folder, then you will need to ensure that you are including the correct project library when you deploy your code to your application container. If the Struts 2 Project Library files are not included when you deploy, this error will also occur.

Floatstone answered 27/1, 2015 at 13:19 Comment(0)
G
0

Make sure your struts2 library include in you deploy project. Add your struts2 library under WEB-INF file. Then add that to your build path.

Gery answered 3/7, 2015 at 6:21 Comment(0)
T
0

I was facing the same problem. Everybody was suggesting that my jar version was wrong but the problem was different.

I was adding the required jar in project, but that was not working.

So removed the jar from project and added those jar in my TOMCAT server lib folder and that worked.

Terza answered 9/9, 2015 at 5:10 Comment(0)
L
0

Starting with Struts 2.5 the StrutsPrepareAndExecuteFilter has been moved to the org.apache.struts2.dispatcher.filter package (without the "ng" in the package).

Lancey answered 19/5, 2016 at 18:57 Comment(0)
C
0

Another solution, if the rest of answers doesn't work for you

If you put the right package path (without .ng..) and you still get:

java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter

I had the same problem but none of this solutions works, because I got the same error using the right path but the reason was how the class loader load the classes.

The solution is to set in the WAS "Classes loaded with local class loader first (parent last)"

To do this:

  • Click on WebSphere enterprise applications.
  • Choose your enterprise application
  • Click on Manage Modules.
  • Click on your module.
  • "Select Classes loaded with local class loader first (parent last)" from the Class loader order drop down list.
  • Click on OK.
  • Click on Save.
  • restart the websphere server (or virtual server in my case).

If this work for you then the best way of doing this is setting an deployment.xml in the EAR project, so in futures deployment this is setted automated:

<?xml version="1.0" encoding="UTF-8"?> 
<appdeployment:Deployment 
        xmi:version="2.0" 
        xmlns:xmi="http://www.omg.org/XMI" 
        xmlns:appdeployment=" 
http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi"> 

        <deployedObject xmi:type="appdeployment:ApplicationDeployment" 
startingWeight="10"> 

                <modules 
                        xmi:type="appdeployment:WebModuleDeployment" 
                        startingWeight="10000" 
                        uri="<your war name>" 
                        classloaderMode="PARENT_LAST" /> 
                <classloader mode="PARENT_LAST" /> 
        </deployedObject> 
</appdeployment:Deployment>

I found out the solution here: Solution - class loader configuration in WAS

Cretaceous answered 26/10, 2018 at 13:51 Comment(0)
I
0

the solution is in pom.xml;

<dependencies>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.3.1.2</version>
    </dependency>
</dependencies>


<packaging>war</packaging>
<build>
    <finalName>struts-2.3-hello-world-example</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webXml>web\WEB-INF\web.xml</webXml>
            </configuration>
        </plugin>
    </plugins>
</build>

i can see this, in this video; https://www.youtube.com/watch?v=q4IhM4GBhF8

Impregnable answered 7/3, 2019 at 17:31 Comment(0)
L
0

in my case, i was using 2.3.3 with "org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter" following the original struts guide in the oficial page, i just changed my version to 2.5 and it worked

Lysippus answered 25/2, 2020 at 18:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.