How to use MOXy as default JAXB implementation? [message #1822910] |
Mon, 16 March 2020 16:23 |
Nils Loose Messages: 5 Registered: September 2017 |
Junior Member |
|
|
Dear experts,
in preparation for migrating an RCP application that makes use of JAXB for storing/loading XML data from Java 8 to Java 11, I'm currently trying to switch to MOXy's JAXB implementation. To do so, I
- added the EclipseLink update site to my target platform definition
- added dependencies to the jakarta.xml.bind-api and org.eclipse.persistence.moxy bundles to the manifest files of all bundles that make use of JAXB
- tried different ways to configure MOXy as the JAXB implementation to be used
Depending on which way I tried, I ran into different problems. According to the infos on the EclipseLink site, the way to do it is putting a file named jaxb.properties next to the domain classes, containing the entry javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory. When doing so, when the application starts and tries to unmarshal some stored objects, I get the following exception:
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:232)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:345)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632)
...
According to the JAXBContext JavaDoc, there are other ways to specify the JAXB implementation:
- setting the system property JAXB_CONTEXT_FACTORY (this would be my preferred option)
- using a file named javax.xml.bind.JAXBContext in /META-INF/services/
When trying those options, I got a different exception:
java.lang.NullPointerException
at javax.xml.bind.ContextFinder.handleClassCastException(ContextFinder.java:114)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:254)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:240)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:375)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632)
...
I'm not exactly sure what is causing the NullPointer here, but the handleClassCastException() method triggering it is called with the parameter values com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl for originalType and javax.xml.bind.JAXBContext for targetType.
Any hints on what I'm doing wrong here and how to fix it would be appreciated. Thanks in advance and stay healthy!
Best regards,
Nils
|
|
|
Powered by
FUDForum. Page generated in 0.02153 seconds