I validate but it's not working on my computer.
What can I do if I want it's works for me :(
Implementation of JAXB-API has not been found on module path or classpath.
Resolved
Comments (7)
- Popular
- New
- Old
You must be signed in to leave a comment
Thomas
14 September 2023, 07:00solution
I'm old an can not read that screenshots very well ;) but as it looks like you mixed sources (javax and sun [core, impl]) I do not know if packages are compatible or import paths match. JAXB is now under the hood of Eclipse (Jakarta). So you either
1. get all libs from javax (and not sun) and it should work out of the box
2. you switch to jakarta sources. Then you need to adapt imports for testing (replace javax with jakarta) and to validate you have to edit that back to javax
(and I'm nearly sure you do not need javax.activation)
edit: tried JAXB and it is enough to get the lib: jakarta.xml.bind-api:4.0.0
the import then is then eg:
import jakarta.xml.bind.JAXB;
or
import jakarta.xml.bind.JAXBContext;
+3
matemate123
14 September 2023, 08:11
I use this library (jakarta.xml.bind-api:4.0.0). 0 errors but still the same result :
Exception in thread "main" jakarta.xml.bind.JAXBException: Implementation of Jakarta XML Binding-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: org.glassfish.jaxb.runtime.v2.ContextFactory]
at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:252)
at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:240)
at jakarta.xml.bind.ContextFinder.find(ContextFinder.java:381)
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:605)
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:546)
at com.codegym.task.task33.task3307.Solution.convertFromXmlToNormal(Solution.java:27)
at com.codegym.task.task33.task3307.Solution.main(Solution.java:20)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jaxb.runtime.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:521)
at jakarta.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:113)
at jakarta.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:146)
at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:250)
... 6 more
+2
Thomas
14 September 2023, 09:45solution
sry, I ignored that Jakarta is just the api (interfaces) and you need an implementation. The Jakarta default implementation is the Glassfish server. So you need
org.glassfish.jaxb:jaxb-runtime:4.0.3 (newest is 4.0.3, then you probably should pick also api 4.0.3)
and
org.glassfish.jaxb:jaxb-core:4.0.3
and this time I also compiled it ☺️
+3
matemate123
15 September 2023, 05:17
When I use:
jakarta.xml.bind-api:4.0.0
org.glassfish.jaxb:jaxb-core:4.0.3
org.glassfish.jaxb:jaxb-runtime:4.0.3
Error:
Exception in thread "main" jakarta.xml.bind.JAXBException: Implementation of Jakarta XML Binding-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: org.glassfish.jaxb.runtime.v2.ContextFactory]
at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:252)
at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:240)
at jakarta.xml.bind.ContextFinder.find(ContextFinder.java:381)
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:605)
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:546)
at com.codegym.task.task33.task3306.Solution.convertToXml(Solution.java:51)
at com.codegym.task.task33.task3306.Solution.main(Solution.java:31)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jaxb.runtime.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:521)
at jakarta.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:113)
at jakarta.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:146)
at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:250)
... 6 more
+2
matemate123
15 September 2023, 05:18
If I used download links from Senned comment:
http://search.maven.org/remotecontent?filepath=com/sun/activation/javax.activation/1.2.0/javax.activation-1.2.0.jar
http://search.maven.org/remotecontent?filepath=javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar
http://search.maven.org/remotecontent?filepath=com/sun/xml/bind/jaxb-core/2.3.0/jaxb-core-2.3.0.jar
http://search.maven.org/remotecontent?filepath=com/sun/xml/bind/jaxb-impl/2.3.0/jaxb-impl-2.3.0.jar
I got error:
wrz 15, 2023 7:03:29 AM com.sun.xml.bind.v2.runtime.reflect.opt.Injector <clinit>
SEVERE: null
java.security.PrivilegedActionException: java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:573)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.<clinit>(Injector.java:197)
at com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.java:81)
at com.sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.java:179)
at com.sun.xml.bind.v2.runtime.reflect.Accessor$FieldReflection.optimize(Accessor.java:285)
at com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.<init>(SingleElementLeafProperty.java:92)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:484)
at com.sun.xml.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:128)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:181)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:514)
........
+1
matemate123
15 September 2023, 05:30
It's so fckng confusing. Now it's work but I don't know why, but let's begin:
I added from Project Structure to lib:
jakarta.xml.bind-api:4.0.0
org.glassfish.jaxb:jaxb-runtime:4.0.3
org.glassfish.jaxb:jaxb-core:4.0.3
but I don't remember order implementation.
✅Transitive dependencies on
Then I change imports in Intellij, and when I open Project Structure I have only one lib connected with xml, not three. If I remember correctly (I was a little shocked and stressed at that moment, because I thought it would never work) only lib was jakarta.xml.bind-api:4.0.0.
Then I added org.glassfish.jaxb:jaxb-runtime:4.0.3 and org.glassfish.jaxb:jaxb-core:4.0.3,
shift + f10 and now I see XML !!
Maybe someone know what was that??
+3
Jakub Raczkowski
23 November 2023, 10:23useful
I tried your sources but didn't work. I found this topic instead:
You've got to download "JAXB RI 3.0.2 standalone ZIP bundle" follow the guidelines. CTRL-SHIFT-ALT-S will open project options, make there a new library (Libraries) and make sure it's added to CodeGym project (Modules).
Then go back to the task which won't work properly, delete all imports related to XML and get fresh imports from the new library (scan the code for red methods/annotations, ALT-M: import) +1