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(
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(
at org.apache.catalina.core.ApplicationFilterConfig.(
at org.apache.catalina.core.StandardContext.filterStart(
at org.apache.catalina.core.StandardContext.start(
at org.apache.catalina.core.ContainerBase.start(
at org.apache.catalina.core.StandardHost.start(
at org.apache.catalina.core.ContainerBase.start(
at org.apache.catalina.core.StandardEngine.start(
at org.apache.catalina.core.StandardService.start(
at org.apache.catalina.core.StandardServer.start(
at org.apache.catalina.startup.Catalina.start(
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(
at org.apache.catalina.startup.Bootstrap.main(

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 someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";
  • jerome

    for me it doesn’t work… 🙁 it’s worse because i have more error message… and i found other tuto and they don’t use this lib directory….

    thus i don’t know what can i do to resolve the first problem : java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher

  • 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

    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.

    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(
    at org.apache.catalina.loader.WebappClassLoader.loadClass(
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(
    at org.apache.catalina.core.StandardWrapper.loadServlet(
    at org.apache.catalina.core.StandardWrapper.load(
    at org.apache.catalina.core.StandardContext.loadOnStartup(
    at org.apache.catalina.core.StandardContext$
    at org.apache.catalina.core.StandardContext$
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$ Source)
    at 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