Tuesday, 20 May 2014

java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet 

I was stuck for last couple of days on this error. So made it the title of this post. A very simple exception - ClassNotFound. We know the jar is missing but what if we know that the exception persists even if the jar is present.

I used Ivy as my dependency manager. To know more on Apache Ivy you can refer to my detailed post I posted earlier.

My directory Structure was

There are two ways to resolve this error

  1. Either move your libraries to WEB-INF/lib . Because this is the folder from where Eclipse searches for corresponding jars. OR
  2. Let Eclipse know that it can search the jars from ivy library folder which is not same as WEB-INF/lib.  So now I will explain how to resolve above problem with 2nd approach in Eclipse.

  • Right click the project and select properties. Now go to Deployment Assembly.

  • Now select Add and select Java build path entries.

  • Ivy option is automatically populated. Select that.

  • And you are done.Select Apply and Ok. ClassNotFound Exception vanishes.

That's it for resolving the issue. This issue may also occur if you genuinely don't have the corresponding jar in the lib folder :P . In that case you have to add the Jar. Dependencies I used for my Spring MVC project were

        <dependency org="org.springframework" name="spring-core" rev="4.0.3.RELEASE"/>
        <dependency org="org.springframework" name="spring-context" rev="4.0.3.RELEASE"/>
        <dependency org="org.springframework" name="spring-web" rev="4.0.3.RELEASE"/>
        <dependency org="org.springframework" name="spring-webmvc" rev="4.0.3.RELEASE"/>
        <dependency org="org.springframework" name="spring-beans" rev="4.0.3.RELEASE"/>

Important Links

t> UA-39527780-1 back to top