0

I have an older widget app, it is using JAXB and now being migrated to Java 11.
I am aware that java.xml.bind/JAXB has been removed in this version, so we are trying to replace it with Jakarta.

We have jakarta.activation.jar and jakarta.xml.bind-api.jar and it works fine for compilation, but not for runtime

when the app starts I am getting this:

javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
  at java.xml.bind/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:232)
  ... ...

The com.sun.xml.internal.* classes were part of rt.jar, which i believe was removed in Java 9, but the latest jakarta source still refers to them... how is that supposed to work? I saw some posts with a similar problem, and typical solution is Add Maven dependency.
I'm not sure about details, but in any case we don't use Maven or Gradle and don't have pom.xml.
Is there anything i can do to make it work?

5
  • How are you running it? What IDE? Command line? Have you added the files to the command line? Are you using the same Java Installation to do both compiling and running/debugging?
    – BBacon
    Commented May 1, 2020 at 13:32
  • stackoverflow.com/questions/53025185/…
    – BBacon
    Commented May 1, 2020 at 13:47
  • github.com/eclipse-ee4j/jaxb-ri/issues/1235
    – BBacon
    Commented May 1, 2020 at 13:53
  • Thanks for the comment! The -cp (classpath) is not honored in Java 11, the second reference is what I saw earlier, but I need to figure out how to use it in my environment (No Maven or other IDE) The app is launched via a script, so it is basically a command line with some -X... and --add-module xxx options ending with the application jar name.
    – Michael
    Commented May 1, 2020 at 14:00
  • So the answer on the first link I sent you (stackoverflow.com/a/53025261/1604170) is probably what you need to change your script. You need to change the METADATA in the released jar file and then execute it using the command line pointing to the added jar packages.
    – BBacon
    Commented May 1, 2020 at 15:18

1 Answer 1

0

Turned out it is not as bad as I thought. rt. jar was broken down to multiple modules and I started looking for the ones I needed. jaxb-runtime.jar looked right to me and I ran strings / grep on it - it indeed had all the com.sun.xml.bind classes in it!

When I added this jar to the ones I had the original error changed to "some-other-class not found" and I had to add more jars until the app was happy. In the end I have this: jakarta.activation.jar, jakarta.xml.bind-api.jar, jaxb-runtime.jar, istack-commons-runtime.jar, stax-ex.jar, FastInfoset.jar, txw2.jar

No changes to manifest, makefile or anything else related to build, purely packaging issue. Big sigh...

Not the answer you're looking for? Browse other questions tagged or ask your own question.