开发者

NoClassDefFoundError when running Tomcat + Spring + Maven project (Eclipse)

What I get is:

java.lang.NoClassDefFoundError: com/mongodb/DB
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:446)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:430)
at org.springframework.util.ReflectionUtils.getAllDeclaredMethods(ReflectionUtils.java:475)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:634)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:573)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1319)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:315)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:394)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:594)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4420)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4733)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
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(NativeMethodAcc开发者_开发问答essorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

This class is inside maven jar (from M2 repository). I added Maven Dependencies to DeploymentAssembly (before I did it i got: java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilter). I use m2e plugin and have my project configured as Maven project. My app is deployed to standard location /.metadata/.plugins/.../tmp0. Inside of WEB-INF/lib I have all necessary jars. Project compiles with no error. What could I do wrong?

One quasi-solution is to add necessary libraries to Tomcat lib directory but I don't want to do that. I want to force Tomcat to use project libraries.


I have had a similar issue when trying to run the mcv-ajax and mvc-basic samples, distributed with Spring 3 (both available at https://src.springframework.org/svn/spring-samples - need an SVN client to download them, something like TortoiseSVN).

I was getting this ClassNotFoundException in my Tomcat6 startup log.

SEVERE: Exception starting filter characterEncodingFilter java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilter
    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.<init>(ApplicationFilterConfig.java:115)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4071)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4725)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    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(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Feb 17, 2012 10:36:18 AM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Feb 17, 2012 10:36:18 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/mvc-basic] startup failed due to previous errors

I could run both Maven Clean and Maven Install goals, with no errors, and the project did not have any classpath errors. I also installed the eclipse Maven Integration for WTP available under the Maven Integration for Eclipse Extras package, as instructed here, but still no luck...

The problem in my case, could be seen in the Markers tab in Eclipse, as a warning (yellow eclamation mark) with a description of Classpath Dependency validator Message and an actual issue of classpath entry org.eclipse.maven2_classpath.container will not be exported or published. Runtime ClassNotFoundExceptions may result.

To solve this issue

  1. right-click on the problem description, and selected quick fix.
  2. Select Mark the associated raw classpath entry as a publish/export dependency
  3. Click on Finish
  4. Do a maven-clean and a maven-install
  5. right click on project, select run on server. Select Tomcat server to run on, and you should see the initial page.

Conclusion The steps described above, worked for me in making the project run successfully in my Eclispe Development Environment. Please give it a try to see if it will work for you.

An alternative solution which also seems to work, is

  1. delete the project from eclipse, including all associated files in the workspace. (delete project directory from workspace as well)
  2. Check the project out again from SVN into the workspace
  3. Import new project in eclipse, but choose Maven\Existing Maven Project
  4. Select the project from the disk and import.

Kind regards,

ta6hbe


It looks like You didn't install the m2eclipse WTP integration.

If so, than this may me the source of wrong deployment. When WTP integration is installed You shouldn't need to change anythong in the deployment descriptor - the plugin should configure Your project automatically. If not, try RMB -> Maven -> Update project configuration, but be sure to install the WTP integration first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜