java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher

This is a common error message for a new Struts2 developer. Many Struts 2 related websites have been reported this problem. Overall, when we see a ClassNotFoundException, we should have a reflection that it is very possible that the build path is wrong somewhere.

java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher

java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:269)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

The problem is caused by the class path.

After you create a dynamic web project under eclipse, you should have the following directory under Project Explorer view.

You may Add External Jars under Java Build Path window like the following:

This works for regular Java project, but does not work for Struts2 web project.

The solution is to simply copy the jar files required to the "lib" directory, then the error message will be gone.
(remove all jars from the class path if you added them before)

Note: Actually, when the error message is something about ClassNotFoundException, we should think in the direction of build path is not correct. Also, different kinds of Java project may use different way to configure build path, e.g., an eclipse plug-in project have to use plug-in to add some library to it.

Category >> Struts 2  
If you want to post code, please put the code inside <pre> and </pre> tags.
  • Sreesha Amjuri

    Wonderful! it really worked. Thank you very much.

  • Admin

    The error msg you got is caused by a different problem. I search it and found that it may be caused by “Tomcat has an optional accelerator component that can improve performance. If you do not include that component, you will get this message, but it can be safely ignored. Unfortunately, there is no way to turn it off other than to include the accelerator component.” Is it true? thanks.

  • satish varma

    hi
    i did whatever explain in above solution to resolve that problem but still i got same error i use eclipse 3.7,tomcat 7.6 java 7.
    CONSOLE OUTPUT:

    May 27, 2012 7:06:19 AM org.apache.catalina.core.AprLifecycleListener init
    INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Broadcom\Broadcom 802.11\Driver;C:\Program Files\Java\jdk1.7.0_04\bin;D:\eclipse-jee-indigo-SR2-win32\eclipse;;.
    May 27, 2012 7:06:19 AM org.apache.coyote.AbstractProtocolHandler init
    INFO: Initializing ProtocolHandler ["http-bio-8080"]
    May 27, 2012 7:06:20 AM org.apache.coyote.AbstractProtocolHandler init
    INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
    May 27, 2012 7:06:20 AM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 819 ms
    May 27, 2012 7:06:20 AM org.apache.catalina.core.StandardService startInternal
    INFO: Starting service Catalina
    May 27, 2012 7:06:20 AM org.apache.catalina.core.StandardEngine startInternal
    INFO: Starting Servlet Engine: Apache Tomcat/7.0.6
    May 27, 2012 7:06:20 AM org.apache.catalina.startup.HostConfig deployDescriptor
    INFO: Deploying configuration descriptor springmvc.xml from C:\myworkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\conf\Catalina\localhost
    May 27, 2012 7:06:20 AM org.apache.catalina.startup.SetContextPropertiesRule begin
    WARNING: [SetContextPropertiesRule]{Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:springmvc’ did not find a matching property.
    May 27, 2012 7:06:20 AM org.apache.catalina.core.ApplicationContext log
    INFO: Marking servlet dispatcher as unavailable
    May 27, 2012 7:06:20 AM org.apache.catalina.core.StandardContext loadOnStartup
    SEVERE: Servlet /springmvc threw load() exception
    java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1488)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:996)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4741)
    at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5062)
    at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5057)
    at java.util.concurrent.FutureTask$Sync.innerRun(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)

    May 27, 2012 7:06:20 AM org.apache.coyote.AbstractProtocolHandler start
    INFO: Starting ProtocolHandler ["http-bio-8080"]
    May 27, 2012 7:06:20 AM org.apache.coyote.AbstractProtocolHandler start
    INFO: Starting ProtocolHandler ["ajp-bio-8009"]
    May 27, 2012 7:06:20 AM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 453 ms
    May 27, 2012 7:06:27 AM org.apache.catalina.core.StandardWrapperValve invoke
    INFO: Servlet dispatcher is currently unavailable