0

I have built a very simple application using Struts 2, I have searched a lot and tried everything but can not get away from this exception :

 java.lang.ClassNotFoundException: org.apache.Struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
        at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:506)
        at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:488)
        at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:115)
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4854)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5546)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

My pom.xml file is :

   <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Struts2tutorial</groupId>
    <artifactId>Struts2tutorial</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencies>

       <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.3.15</version>
</dependency>
<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>2.3.15</version>
</dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src/struts/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
        <finalName>${project.artifactId}</finalName>
    </build>
</project>

My web.xml is:

<?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>Struts2tutorial</display-name>

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

  <welcome-file-list>
    <welcome-file>/login.jsp</welcome-file>
  </welcome-file-list>
</web-app>

I get this exception when I compile it on tomcat,am using tomcat 7,please help.

6
  • duplicate stackoverflow.com/questions/24759956/… Commented Dec 28, 2015 at 12:15
  • 1
    @pmverma it has no correct answer please check before marking it as duplicate. Commented Dec 28, 2015 at 12:17
  • Your version struts2-core is recent version which contains org.apache.Struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter. It seems you have problem with the build process. How are you compiling, using maven? Commented Dec 28, 2015 at 12:25
  • @pmverma no am not using maven to build, am directly running it on tomcat server. Commented Dec 28, 2015 at 12:27
  • that's why. try mvn clean install from project root directory. A war file will be created under target folder.You can use this file to run in tomcat. Commented Dec 28, 2015 at 12:29

1 Answer 1

1

I think your class define in web.xml is wrong. its org.apache.struts2.dispatcher.filter.ng.StrutsPrepareAndExecuteFilter not org.apache.Struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

Sign up to request clarification or add additional context in comments.

2 Comments

no the path is fine, as I have extracted the jar file and saw the class inside, the path is correct.
as mentioned please change org.apache.Struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter to org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter small s not capts, in web.xml the stacktrace also shows that at least it is one the problems

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.