HTTP状态500 - 处理程序处理失败;嵌套异常是java.lang.NoClassDefFoundError:

时间:2015-01-10 07:59:04

标签: java spring maven tomcat noclassdeffounderror

我试图将外部jar文件集成到我的项目中。 (mambu的模型-V3.8.10.jar)

但是我收到了这样的错误消息:

HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: com/mambu/loans/shared/model/LoanAccount    


org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: com/mambu/loans/shared/model/LoanAccount
org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1287)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)    

根本原因:

java.lang.ClassNotFoundException: com.mambu.loans.shared.model.LoanAccount
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
java.lang.Class.getDeclaredMethods0(Native Method)
java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
java.lang.Class.getDeclaredMethods(Class.java:1962)
com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:662)
com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:356)
com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies(ConstructorBindingImpl.java:151)
com.google.inject.internal.InjectorImpl.getInternalDependencies(InjectorImpl.java:585)
com.google.inject.internal.InjectorImpl.cleanup(InjectorImpl.java:543)
com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:529)
com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:847)
com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:772)
com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:256)
com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:205)
com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:853)
com.google.inject.internal.InjectorImpl.getProviderOrThrow(InjectorImpl.java:967)
com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1000)
com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:961)
com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)
com.mambu.apisdk.MambuAPIFactory.getLoanService(MambuAPIFactory.java:86)
comm.app.starter.HomeController.Opaaaaana(HomeController.java:167)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:483)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)    

这是我的POM xml:

http://maven.apache.org/maven-v4_0_0.xsd">     4.0.0     com.springapp     kapiv2     战争     1.0-SNAPSHOT     KAPI

<properties>
    <spring.version>4.1.1.RELEASE</spring.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.mambu</groupId>
        <artifactId>mambumodels</artifactId>
        <version>3.8.10</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/mambu-models-V3.8.10.jar
        </systemPath>
        <optional>false</optional>
    </dependency>
   <!-- <dependency>
        <groupId>com.cenqua.clover</groupId>
        <artifactId>clover</artifactId>
        <version>3.0.2</version>
    </dependency>-->

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.1</version>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>1.7.1</version>
        <scope>compile</scope>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>javax.jdo</groupId>
        <artifactId>jdo-api</artifactId>
        <version>3.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>3.0</version>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.8.5</version>
        <optional>false</optional>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-dev</artifactId>
        <version>2.7.0</version>
    </dependency>
   <!-- <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>1.5.3</version>
    </dependency>-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.2.1</version>
    </dependency>

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.5</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <finalName>kapi</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

    </plugins>
</build>

如果你搜索NoClassDefFoundError,谷歌会有很多结果 - 但是没有一个能让我感到恶心。

你可以告诉我为什么会收到这样的错误吗? 感谢

4 个答案:

答案 0 :(得分:3)

问题是在运行时缺少运行此函数所需的jar文件。所以我把它添加到MAVEN

           <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/myTESTapplication/WEB-INF/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>   

答案 1 :(得分:0)

您在系统范围中添加依赖项。这意味着,当您对应用程序进行编码时,您的ide会很好地将其作为依赖项,但是在运行代码时,服务器应该在classpath或某个lib文件夹下将其置于正确运行的依赖项之前。在这个范围内,maven和tomcat不会代表你做任何技巧。

http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html是关于classpath的tomcat引用,当使用系统范围时,它会为webapp下的jar位置建议WEB-INF / lib。如果你想使用maven为你提供类,你应该使用编译目标并拥有一个repo来为你提供jar。更多信息java.lang.NoClassDefFoundError: in eclipse maven

答案 2 :(得分:0)

问题可能不是该类缺失 - 它可能存在,但未能正确初始化。例如静态代码块发生异常。

这个答案很好地解释了Why am I getting a NoClassDefFoundError in Java?

答案 3 :(得分:0)

就我而言,我设置了一个引发异常并导致此错误的 static final String,对此值进行硬编码解决了问题:

private static final String SERVICE_NAME = ManifestProvider.getServiceName();