0

I have a problem with JAXB Marshalling. When I run the programm in an IDE (In my case Intelli J) everything works fine and no errors get thrown. But when I try to start a jar of that programm manually the following error gets thrown:

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]

The full error message is:

Exception in thread "ForkJoinPool-2-worker-1" 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 javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:278)
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:421)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
        at networkManager.Marshall.output(Marshall.java:54)
        at networkManagerSockets.ClientReciveSocket.recive(ClientReciveSocket.java:95)
        at networkManagerSockets.ClientReciveSocket.run(ClientReciveSocket.java:76)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
        at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:276)
        ... 12 more

I have the following dependencies for JAXB in my build.gradle:

implementation "com.sun.xml.bind:jaxb-impl:3.0.2"
implementation "javax.xml.bind:jaxb-api:2.3.1"
implementation "com.sun.istack:istack-commons-runtime:4.1.1"
implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.1'

My java version is 17.0.3.1

Does anyone have a solution for the problem or knows why it works in the IDE?

joes00
  • 1
  • 1
  • 2
  • You're specifying incompatible implementations `com.sun.xml.bind:jaxb-impl:3.0.2` is not an implementation of `javax.xml.bind:jaxb-api:2.3.1`, you need to use either `com.sun.xml.bind:jaxb-impl:2.3.6`, or use `jakarta.xml.bind:jakarta.xml.bind-api:3.0.1` instead of `javax.xml.bind:jaxb-api:2.3.1` (but then you also need to change the jaxb-runtime version!) – Mark Rotteveel Jun 04 '22 at 13:23
  • With version 3.0, things moved from the `javax` package namespace to the `jakarta` package namespace. – Mark Rotteveel Jun 04 '22 at 13:26
  • Thanks for the quick response. Sadly I still get the same error. I added the full error message to my question above. Do you have an explanation why it works when executing in intelli j but not when I run it through the terminal as a jar? – joes00 Jun 04 '22 at 13:52
  • @MarkRotteveel just tagging you that you get a notification – joes00 Jun 05 '22 at 08:07
  • Sorry, I'm drawing a blank. Can you update the dependencies if you changed those. Also, exactly how are you running it when it fails? – Mark Rotteveel Jun 05 '22 at 08:19
  • @MarkRotteveel Hey I finally fixed the problem. It was related to transitive dependencies. Creating a fat jar solved the problem (needed a plugin because I used gradle) – joes00 Jun 05 '22 at 11:05
  • Please check this it may help you https://stackoverflow.com/questions/49113207/completablefuture-forkjoinpool-set-class-loader – Dev Jun 24 '22 at 08:38

0 Answers0