MOXy is configured but is being ignored
Contents
Check the Implementation
The first time I tried to use MOXy, I was not able to tell whether I had actually configured it correctly. So, first of all, you may want to check which implementation of JAXB is being used for the domain classes you are trying to handle.
The following code checks to see which implementation is used to handle YourDomainClass
.
|
|
Set Up MOXy
Create a jaxb.properties
file containing this:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
This file needs to be placed in the same packages as the domain classes you want MOXy to handle.
JAXB Libraries and JARs
The module java.se.ee
was removed from Java 11. See JEP-320. This module includes JAXB (and JAX-WS and others). To use JAXB in Java 11 and newer, you therefore need to add it to your project as a separate library. The contents of my pom.xml:
|
|
In the above POM, the following artifacts are shown:
Library | Notes |
---|---|
eclipselink | Contains MOXy classes as well as other libraries provided by the EclipseLink project. |
jaxb-api | Version 2.3.1 of the JAXB API, containing javax.xml.bind . Remember, JAXB is just an API! Maven tells me there is a newer version: 2.4.0-b180830.0359. But I have never used it. |
jaxb-core | This contains core classes required by the runtime modules. |
jaxb-runtime | This is the Glassfish reference implementation of JAXB. But not the only implementation, of course. It is part of Project Metro - which also includes the JAX-WS reference implementation, among other libraries. |
jaxb-impl | The old JAXB Runtime module. Version 2.3.1 is from 2018. YOU DO NOT NEED IT TO RUN MOXy. If you don’t use MOXy, You should probably be using the Metro jaxb-runtime, rather than this. |
There is also this:
|
|
This is a standalone bundle of the Glassfish (Metro) JAXB reference implementation. You can find the xjc
and schemagen
tools inside this JAR, since these tools are also no longer a part of the core Java distribution. You can download the JAR from here, unzip it, and then look in the bin
directory to find the tools' binaries.
Deploy MOXy
Remember to ensure the MOXy properties file is copied from the source folder to the correct target, as part of the Maven/Ant/Gradle build process.
For a Maven-based project, the following section will ensure the properties file is copied correctly:
|
|
Author northCoder
LastMod 29-Jun-2020