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?