Tomcat8.5 and Openjdk11 NoClassDefFoundError: Could not initialize class org.apache.cxf.attachment.AttachmentUtil

Tomcat8.5 and Openjdk11 NoClassDefFoundError: Could not initialize class org.apache.cxf.attachment.AttachmentUtil

我正在将 Java 应用程序迁移到 Tomcat 8.5 上 运行 的 OpenJDK11。应用程序和 tomcat 启动没有任何问题。使用 JDK1.8 我没有任何异常或错误但是当使用另一个 Webservice 和 运行 tomcat 使用 OpenJDK11 调用应用程序时,我收到以下错误:

02-Apr-2019 13:27:07.225 SEVERE [http-nio-0.0.0.0-9000-exec-8] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [CXFServlet] in context with path [/ApplicationName] threw exception [Servlet execution threw an exception] with root cause
 java.lang.NoClassDefFoundError: Could not initialize class org.apache.cxf.attachment.AttachmentUtil
        at org.apache.cxf.interceptor.AttachmentInInterceptor.handleMessage(AttachmentInInterceptor.java:55)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
        at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
        at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:220)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:613)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Thread.java:834)

当我打开此应用程序的 Eclipse 工作区时,我也可以打开并查看 AttachmentUtil class。这个 class 包含在 jar 'cxf-core-3.3.1' 中,它取决于' org.apache.cxf:cxf-rt-frontend-jaxws:jar:3.3.1:'

这是我的 mvn 依赖树:

 --- maven-dependency-plugin:2.8:tree (default-cli) @ XmlBeans ---
 de.somename.rail.sresb.entireXComServer:XmlBeans:jar:2.12.1
 +- org.apache.cxf:cxf-rt-frontend-jaxws:jar:3.3.1:compile
 |  +- xml-resolver:xml-resolver:jar:1.2:compile
 |  +- org.ow2.asm:asm:jar:7.0:compile
 |  +- org.apache.cxf:cxf-core:jar:3.3.1:compile
 |  |  +- com.fasterxml.woodstox:woodstox-core:jar:5.0.3:compile
 |  |  +- org.apache.ws.xmlschema:xmlschema-core:jar:2.2.4:compile
 |  |  +- org.glassfish.jaxb:jaxb-xjc:jar:2.3.2:compile
 |  |  |  +- org.glassfish.jaxb:xsom:jar:2.3.2:compile
 |  |  |  +- org.glassfish.jaxb:codemodel:jar:2.3.2:compile
 |  |  |  +- com.sun.xml.bind.external:rngom:jar:2.3.2:compile
 |  |  |  +- com.sun.xml.dtd-parser:dtd-parser:jar:1.4.1:compile
 |  |  |  +- com.sun.istack:istack-commons-tools:jar:3.0.8:compile
 |  |  |  |  \- org.apache.ant:ant:jar:1.10.5:compile
 |  |  |  |     \- org.apache.ant:ant-launcher:jar:1.10.5:compile
 |  |  |  \- com.sun.xml.bind.external:relaxng-datatype:jar:2.3.2:compile
 |  |  \- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:compile
 |  |     \- jakarta.activation:jakarta.activation-api:jar:1.2.1:compile
 |  +- org.apache.cxf:cxf-rt-bindings-soap:jar:3.3.1:compile
 |  |  +- org.apache.cxf:cxf-rt-wsdl:jar:3.3.1:compile
 |  |  |  \- wsdl4j:wsdl4j:jar:1.6.3:compile
 |  |  \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:3.3.1:compile
 |  +- org.apache.cxf:cxf-rt-bindings-xml:jar:3.3.1:compile
 |  +- org.apache.cxf:cxf-rt-frontend-simple:jar:3.3.1:compile
 |  +- org.apache.cxf:cxf-rt-ws-addr:jar:3.3.1:compile
 |  |  \- org.apache.cxf:cxf-rt-ws-policy:jar:3.3.1:compile
 |  |     \- org.apache.neethi:neethi:jar:3.1.1:compile
 |  +- javax.annotation:javax.annotation-api:jar:1.3.1:compile
 |  +- com.sun.activation:javax.activation:jar:1.2.0:compile
 |  +- org.apache.geronimo.specs:geronimo-ws-metadata_2.0_spec:jar:1.1.3:compile
 |  +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.4.0-b03:compile
 |  +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
 |  \- org.jboss.spec.javax.rmi:jboss-rmi-api_1.0_spec:jar:1.0.6.Final:compile
 +- javax.xml.bind:jaxb-api:jar:2.3.0:compile
 +- org.glassfish.main.javaee-api:javax.jws:jar:3.1.2.2:compile
 +- javax.xml.ws:jaxws-api:jar:2.3.1:compile
 |  \- javax.xml.soap:javax.xml.soap-api:jar:1.4.0:compile
 +- javax.activation:javax.activation-api:jar:1.2.0:compile
 +- org.glassfish.jaxb:jaxb-runtime:jar:2.3.1:compile
 |  +- org.glassfish.jaxb:txw2:jar:2.3.1:compile
 |  +- com.sun.istack:istack-commons-runtime:jar:3.0.7:compile
 |  +- org.jvnet.staxex:stax-ex:jar:1.8:compile
 |  \- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.15:compile
 +- com.sun.xml.bind:jaxb-core:jar:2.3.0:compile
 +- com.sun.xml.bind:jaxb-impl:jar:2.3.0:compile
 +- com.sun.xml.ws:rt:jar:2.3.0:compile
 |  +- com.sun.xml.ws:policy:jar:2.7.2:compile
 |  +- org.glassfish.gmbal:gmbal-api-only:jar:3.1.0-b001:compile
 |  |  \- org.glassfish.external:management-api:jar:3.0.0-b012:compile
 |  +- com.sun.xml.stream.buffer:streambuffer:jar:1.5.4:compile
 |  +- org.jvnet.mimepull:mimepull:jar:1.9.7:compile
 |  +- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile
 |  +- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
 |  +- com.sun.org.apache.xml.internal:resolver:jar:20050927:compile
 |  \- javax.jws:jsr181-api:jar:1.0-MR1:compile
 \- com.sun.xml.ws:jaxws-rt:jar:2.3.0:compile

感谢任何有用的提示。提前致谢。

NoClassDefFoundError: Could not initialize class org.apache.cxf.attachment.AttachmentUtil 表示 JVM 未能初始化 AttachmentUtil class.

Apache CXF 3.3.X 应该支持 JDK 11 as per FAQ。您想要在 NoClassDefFoundError 异常上使用异常断点调试启动并查看根本原因是什么。看起来 static 字段或块在加载 AttachmentUtil class 时未能 运行 但根本原因被抑制了。

我也遇到了同样的问题。到目前为止,添加此依赖项有所帮助:

        <dependency>
            <groupId>com.sun.activation</groupId>
            <artifactId>javax.activation</artifactId>
            <version>1.2.0</version>
        </dependency>

应用程序有效,但我现在收到此警告:

java.lang.IllegalAccessException: class org.apache.tomcat.util.buf.ByteBufferUtils cannot access class jdk.internal.ref.Cleaner (in module java.base) because module java.base does not export jdk.internal.ref to unnamed module @5ce81285

在精简期后解决了这个问题。在 2 个包模块的 pom 中添加了一些缺少的 CXF 和 Java EE 依赖项。

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0.1</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.2</version>
</dependency>
<dependency>
   <groupId>javax.annotation</groupId>
   <artifactId>javax.annotation-api</artifactId>
   <version>1.3.1</version>
</dependency>
<dependency>
    <groupId>com.sun.activation</groupId>
    <artifactId>javax.activation</artifactId>
    <version>1.2.0</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-core</artifactId>
    <version>${cxf.version}</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.3.0</version>    
</dependency>