OpenJDK 11: java.lang.NoClassDefFoundError: jakarta/xml/ws/Service when calling a SOAP web service

3k views Asked by At

I am trying to migrate an Oracle JDK 8 application that calls a SOAP web service to Adopt OpenJDK 11 (jdk-11.0.8.10-hotspot). I downloaded jaxws-ri-3.0.0-M4 from the Maven repository, ran wsimport on the WSDL file, it generated a bunch of proxy classes (similar to what I had before, but with different package references), I added the JARs from jaxws-ri-3.0.0-M4 to the project, updated the names of the package imports in the application and it built fine (no compile errors). But when I run the application from Eclipse, I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: jakarta/xml/ws/Service
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at net.codejava.Test.main(Test.java:31)
Caused by: java.lang.ClassNotFoundException: jakarta.xml.ws.Service
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 10 more

It looks like the exception is caused by the application trying to instantiate a web service client proxy class generated by wsimport.

PROGRAM CODE:

TestWS ws = new TestWS(wsdlUrl);

PROXY CLASS:

public class TestWS
    extends Service

If I select the Service class and choose the Open Declaration option from the context menu, it takes me to the jakarta.xml.ws-api.jar metadata:

// Compiled from Service.java (version 1.8 : 52.0, super bit)
public class jakarta.xml.ws.Service {
  
  // Field descriptor #34 Ljakarta/xml/ws/spi/ServiceDelegate;
  private jakarta.xml.ws.spi.ServiceDelegate delegate;

The JAR holding the implementation of the Service class is there, so why am I getting this error?

I read multiple articles (StackOverflow, GitHub, etc) that address similar issues caused by the apps migrating to JDK 11 but I could not find a solution that would work for me. Most articles recommend defining proper Maven dependencies, but our app is not using Maven (this is outside of my control), so I just copied the JARs manually, which I assumed would do the same.

Is there something I am missing? Is there a better way to call a SOAP web service from Java? It took me a while to figure out how to do it with Oracle JDK 8, but eventually it worked, and I am totally stuck trying to do the same with OpenJDK 11.

Please keep in mind that I am not not proficient in Java (I have many years of .NET experience, but this is my first Java assignment).

Thanks.

0

There are 0 answers