Showing posts with label eclipse spring tomcat ClassNotFoundException classloading. Show all posts
Showing posts with label eclipse spring tomcat ClassNotFoundException classloading. Show all posts

Friday, August 21, 2009

Spring ContextLoaderListener ClassNotFoundException

I ran a Java web application with Maven, Tomcat in Eclipse. When the application started, Eclipse console has the exception:
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

Of course, I did not forget to define Spring dependency in Maven pom.xml. But when I checked the deployment at
ECLIPSE_WORKSPACE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\APPLICATION\WEB-INF\lib
, there was no Jar indeed. So it looked like something went wrong with Eclipse/Tomcat/Maven deployment.

I did a couple of things to make it work.
1. Get rid of duplicated classes. For example, the dependency on spring-aspects also brings in spring-beans and spring-core, which are already part of spring dependency. Tip: use "mvn dependency:tree" to the dependency tree. So I need to exclcude it by
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>2.5.6</version>
<!-- exclude spring-beans which is part of spring-2.5.6.jar -->
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
</exclusions>
</dependency>
2. Right click project > Maven > Update Project Configuration. Disable and re-enable Maven dependency management if necessary.

Now I found all the required jars in the right place. I started the application and no error!

This seems to be a glitch with Eclipse Maven plugin. I need to keep an eye on it.