0

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.

Alek Davis
  • 10,628
  • 2
  • 41
  • 53
  • Java EE has been migrated to eclipse and renamed. Hence you need a wsimport step that is in sync with your runtime. The simplest may be to stay with java 8 for now. – Thorbjørn Ravn Andersen Oct 08 '20 at 07:29
  • @ThorbjørnRavnAndersen: Thanks. Are you sayin that it is because wsimport I used did not come not from AdoptOpenJDK? In the other words, wsimport and OpenJdk must come from the same vendor? I know that people were able to call SOAP web services after migrating to JDK 11. Is this because they use something other than AdoptOpenJDK? – Alek Davis Oct 08 '20 at 14:47
  • Are you using Maven or Gradle for your project? – Boris Oct 08 '20 at 15:59
  • @Boris: No, we don't. I am testing this with a simple stand-alone app, so I am flexible with what I use, but I eventually have to incorporate it in a project that is owned by a bigger organization, and it is not using any dependency frameworks (maven, etc). – Alek Davis Oct 08 '20 at 16:35
  • @AlekDavis The M4 bit means that it is milestone 4, not a finished release - use an older one. Read the release notes carefully to ensure you get what you need for Java 11, as the standard runtime has been slimmed considerably. – Thorbjørn Ravn Andersen Oct 10 '20 at 21:53
  • @ThorbjørnRavnAndersen: Thank you. So, if the last pre-milestone version shows 65 dependencies in Maven (1 provide + 64 managed), does it mean that I need to deploy all the JARs from these 65 dependencies? – Alek Davis Oct 12 '20 at 01:20
  • @ThorbjørnRavnAndersen: Thanks for the suggestion. I used v2.3.3 of jaxws-ri to generate proxy classes, and added dependencies via Maven, just to test and it worked. Now I need to figure out runtime dependencies (JARs) and make it work without Maven. – Alek Davis Oct 12 '20 at 21:58
  • @ThorbjørnRavnAndersen: I created an exact replica of my working test app that uses Maven, included the JAR files referenced in Maven dependencies via the build path settings and I am back to the original error. Any idea how to copy all runtime settings from Maven configuration to a non-Maven project? – Alek Davis Oct 13 '20 at 00:37
  • Okay, I fixed it by adding the JAR files from Maven dependencies under the CLASSPATH tree instead of the modules. It's working now. Many thanks @ThorbjørnRavnAndersen – Alek Davis Oct 13 '20 at 01:18

0 Answers0