java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet error
Asked Answered
H

1

6

Not sure why am I getting this error. Lots of similar questions here but none have worked for me till now.

My ivy file is

<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
    <info
        organisation=""
        module="knoxWeb"
        status="integration">
    </info>

    <dependencies>
        <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"/>
    </dependencies>
</ivy-module>

and 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" 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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Knox Web Interface</display-name>

    <servlet>
    <servlet-name>action</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
   </servlet>
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

I have resolved ivy. Still getting the error. Also i can see the Class in my eclipse.

enter image description here

I am really stuck at this. Any help or suggestion is appreciated.

PS : I also tried adding < dependency org="org.springframework" name="spring" rev="2.5.6"/> but ivy does not resolve. I get

Some projects fail to be resolved
Impossible to resolve dependencies of #TestWebProject;working@BLT430LT3201C
download failed: com.oracle.toplink#toplink;10.1.3!toplink.jar
unresolved dependency: com.oracle#oc4j;1.0: not found
unresolved dependency: com.oracle#toplink-essentials;2.41: not found
unresolved dependency: javax.ejb#ejb;3.0: not found
download failed: com.bea.wlplatform#commonj-twm;1.1!commonj-twm.jar
unresolved dependency: jexcelapi#jxl;2.6.6: not found
download failed: javax.jms#jms;1.1!jms.jar
download failed: javax.faces#jsf-api;1.1!jsf-api.jar
download failed: javax.resource#connector;1.0!connector.jar

Not sure if this has anything to do with above problem. I am searching http://mvnrepository.com/artifact/org.springframework for all dependency info.

My project structure is

enter image description here

WEB-INF/lib directory is empty.

Source : http://opensourceforgeeks.blogspot.in/2014/05/javalangclassnotfoundexception.html

Heresy answered 20/5, 2014 at 16:58 Comment(8)
Double check content of web-inf/lib folder of your warFollowthrough
That folder is empty.Heresy
Then it cannot work. There shall be all jars. It is deployment issue. But I have no Ivy knowledge.Followthrough
ivy should populate the WEB-INF/lib directory in the build area. This directory should be empty in your source tree.Tildie
Added the directory structure of my project to the question .Heresy
Ivy should produce a war file. Open the war and check to see if you have the spring jars in your WEB-INF/lib directory. if not (seems likely) then you have an Ivy config error (as in, it is not producing the output you desire).Tildie
I meant war that was built, not source project. Is that directory empty?Followthrough
Yeah you guys are right. We either need to add jar files to WEB-INF/lib folder or add ivy folder to java deployment assembly build path. Thanks a ton!Heresy
H
23

Thanks a lot guys for your valuable comments. You are all right. Jar files must be in WEB-INF/lib. Or you can tell Eclipse that it can find the jars in additional location and not just WEB-INF/lib.

How do we do that?

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

enter image description here

  • Now select Add and select Java build path entries.

enter image description here

  • Ivy option is automatically populated. Select that.

enter image description here

  • And you are done.Select Apply and ok. Classnotfound Exception vanishes.

enter image description here

Heresy answered 20/5, 2014 at 17:33 Comment(1)
really nice help, but when I have created fresh project that time also it was not getting added why?Thomasinathomasine

© 2022 - 2024 — McMap. All rights reserved.