带有java.lang.NoClassDefFoundError的servlet上的严重异常

时间:2017-03-07 16:44:48

标签: java-8 tomcat8 openjdk servlet-listeners

我在运行此java版OpenJDK运行时环境的tomcat8上得到此异常(build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)

SEVERE [http-nio-80-exec-9] 

org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [restSdkService] in context with path [/RestService] threw exception [java.lang.NoClassDefFoundError: Could not initialize class com.example.bean.SomeBean] with root cause
 java.lang.NoClassDefFoundError: Could not initialize class com.example.bean.SomeBean at com.example.service.SomeService.getStuff(SomeService.java:118)
        at sun.reflect.GeneratedMethodAccessor451.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.wink.server.internal.handlers.InvokeMethodHandler.handleRequest(InvokeMethodHandler.java:63)
        at org.apache.wink.server.handlers.AbstractHandler.handleRequest(AbstractHandler.java:33)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)
        at org.apache.wink.server.internal.handlers.CreateInvocationParametersHandler.handleRequest(CreateInvocationParametersHandler.java:54)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)
        at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleSubResourceMethod(FindResourceMethodHandler.java:183)
        at org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleRequest(FindResourceMethodHandler.java:110)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)
        at org.apache.wink.server.internal.handlers.FindRootResourceHandler.handleRequest(FindRootResourceHandler.java:95)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)
        at org.apache.wink.server.internal.handlers.HeadMethodHandler.handleRequest(HeadMethodHandler.java:53)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)
        at org.apache.wink.server.internal.handlers.OptionsMethodHandler.handleRequest(OptionsMethodHandler.java:46)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)
        at org.apache.wink.server.internal.handlers.SearchResultHandler.handleRequest(SearchResultHandler.java:33)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)
        at org.apache.wink.server.internal.log.ResourceInvocation.handleRequest(ResourceInvocation.java:92)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)
        at org.apache.wink.server.internal.log.Requests.handleRequest(Requests.java:76)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
        at org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:63)
        at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:48)
        at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:207)
        at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)
        at org.apache.wink.server.internal.servlet.RestServlet.service(RestServlet.java:119)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
        at org.apache.wink.server.internal.servlet.contentencode.ContentEncodingResponseFilter.doFilter(ContentEncodingResponseFilter.java:122)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
        at psiprobe.Tomcat80AgentValve.invoke(Tomcat80AgentValve.java:40)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1504)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1460)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

这就是我的web.xml的样子:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Wink SDK demo</display-name>
    <description>Demonstration of SDK features</description>
    <filter>
        <filter-name>ContentEncodingResponseFilter</filter-name>
        <filter-class>org.apache.wink.server.internal.servlet.contentencode.ContentEncodingResponseFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>ContentEncodingResponseFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>com.example.listener.ApplicationLifeCycleListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>restSdkService</servlet-name>
        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>

        <init-param>
            <param-name>applicationConfigLocation</param-name>
            <param-value>/WEB-INF/application</param-value>
        </init-param>

        <init-param>
            <param-name>propertiesLocation</param-name>
            <param-value>/WEB-INF/bookmarks.properties</param-value>
        </init-param>

        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.example.WinkApplication</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>restSdkService</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

这是我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.some.service</groupId>
    <artifactId>RestService</artifactId>
    <packaging>war</packaging>

    <version>current-SNAPSHOT</version>


    <parent>
        <groupId>de.some.parent</groupId>
        <artifactId>parent</artifactId>
        <version>current-SNAPSHOT</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.wink</groupId>
            <artifactId>wink-server</artifactId>
            <version>1.1.3-incubating</version>
        </dependency>
        <dependency>
            <groupId>org.apache.wink</groupId>
            <artifactId>wink-client</artifactId>
            <version>1.1.3-incubating</version>
        </dependency>
        <dependency>
            <artifactId>mongo-java-driver</artifactId>
            <groupId>org.mongodb</groupId>
            <version>${mongo-java-driver.version}</version>
        </dependency>
        <dependency>
            <groupId>de.some.entities</groupId>
            <artifactId>someinternalentities</artifactId>
            <version>current-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <groupId>asm</groupId>
                    <artifactId>asm</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>de.some.utils</groupId>
            <artifactId>someinternalutils</artifactId>
            <version>current-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>de.some.lib</groupId>
            <artifactId>someinternallib</artifactId>
            <version>current-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-jaxb-annotations</artifactId>
            <version>2.7.4</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5-20081211</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>apache-log4j-extras</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>net.sf.cron4j</groupId>
            <artifactId>cron4j</artifactId>
            <version>2.2.5</version>
        </dependency>

        <!-- JETTY DEPENDENCIES FOR TESTING -->
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty</artifactId>
            <version>6.1.25</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>6.1.25</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-management</artifactId>
            <version>6.1.25</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>de.some.internal.library</groupId>
            <artifactId>someinternal-svc</artifactId>
            <version>current-SNAPSHOT</version>
        </dependency>

        <!-- JUNIT DEPENDENCY FOR TESTING -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/asm/asm-attrs -->
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm-attrs</artifactId>
            <version>2.2.3</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <filtering>false</filtering>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <filtering>false</filtering>
                <directory>src/main/java</directory>
                <includes>
                    <include>**</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/main/config</directory>
                <filtering>true</filtering>
            </testResource>
            <testResource>
                <filtering>false</filtering>
                <directory>src/test/java</directory>
                <includes>
                    <include>**</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <optimize>true</optimize>
                    <debug>true</debug>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                        </manifest>
                    </archive>
                    <archiveClasses>true</archiveClasses>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

有没有人知道为什么会这样?

1 个答案:

答案 0 :(得分:0)

我们通过删除tomcat在路径/ tomcat8 / work / Catalina / localhost中创建的文件夹来解决问题。

在这里阅读@Jared回答Why am I getting a NoClassDefFoundError in Java?

  

通常这表明我们之前尝试从类路径加载一个类,但由于某种原因它失败了 - 现在我们再次尝试使用该类(因此需要加载它,因为它上次失败了),但我们甚至都没有尝试加载它,因为我们之前未能加载它

并且关于tomcat的工作目录是tomcat在运行时写入所需文件的事实(更多信息请参阅此处tomcat8 configuration reference

  

这个目录将通过名为javax.servlet.context.tempdir的servlet上下文属性(类型为java.io.File)对Web应用程序中的servlet可见,如Servlet规范中所述

,我相信这两件事情彼此相关