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

3

6

I am migrating a Java Application to OpenJDK11 which is running on Tomcat 8.5. Application and tomcat starts withount any problem. With JDK1.8 I don't have any exception or error But when calling application with another Webservice and running tomcat with OpenJDK11 I get following error:

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)

When I open Eclipse workspace for this application I can also open and see AttachmentUtil class. This class is in jar 'cxf-core-3.3.1' included which depends on ' org.apache.cxf:cxf-rt-frontend-jaxws:jar:3.3.1:'

This is my mvn dependeny tree:

 --- 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

Any useful hints are appreciated. Thx in advance.

Zeller answered 2/4, 2019 at 13:43 Comment(0)
M
1

I had right the same problem. Adding this dependency helped so far:

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

The application works, but I now recieve this warning:

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
Muley answered 3/4, 2019 at 6:32 Comment(0)
Z
4

Solved this problem after a lean period. Added some missing CXF and Java EE dependencies in pom's of 2 package modules.

<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>
Zeller answered 3/4, 2019 at 8:52 Comment(2)
I guess this hell waits for some people out there :( But if you want to have a much smoother life, just use the cxf-spring-boot-starter which provides all those dependencies for you - and brings in so many more features, incl. full support for newer JDKs, generation of all JAX-WS classes out-of-the-box and much more. But thanks for documenting, we had similar problems...Colloidal
What helped in my case was adding missing dependency to "javax.activation" and "angus-activation". But the original exception was misleading and what helped to debug/find out what is missing, was adding try/catch as near as possible to the the code which was about to call AttachmentUtil class.Proliferate
H
2

NoClassDefFoundError: Could not initialize class org.apache.cxf.attachment.AttachmentUtil means that JVM failed to initialize the AttachmentUtil class.

Apache CXF 3.3.X should support JDK 11 as per FAQ. You want to debug the startup with exception breakpoint on the NoClassDefFoundError exception and see what was the root cause. It looks likely a static field or block failed to run when loading AttachmentUtil class but the root cause was surpressed.

Hodgkin answered 2/4, 2019 at 14:22 Comment(7)
thank you Karol. But why does it work with JDK 8? I don't have any problem with this Java versionZeller
You won't know until you debug the AttachmentUtil class loading on Java 11.Hodgkin
Ok but I develop on Windows and this application is ony runnable on Linux Suse. I am not able to debug it locallyZeller
I'll try this in maven pom: <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties>Zeller
now I got another NoClassDefFoundError: com/sun/activation/registries/LogSupportZeller
com/sun/activation/registries/LogSupport is one of the classes that is no longer available after Java 9 project Jigsaw modularized the JVM. com.sun.* classes were not supposed to be used in user code and are only available pre Java 9.Hodgkin
I'm not sure that will run anytime.Zeller
M
1

I had right the same problem. Adding this dependency helped so far:

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

The application works, but I now recieve this warning:

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
Muley answered 3/4, 2019 at 6:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.