Issue
I have been using JAXB in a Java project using JDK 8. Having migrated to JDK 11, the JAXB package name is no longer recognized. I have also not found a way to add JAXB as a dependency in gradle. How can I import JAXB into my project?
Solution
You need to include JAXB API and choose from one of the JAXB implementations because JAXB is is no more included by default in the JDK 11. You need to add some dependencies to your build.gradle
.
So first:
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
and if you decide to use for example MOXy, then something like:
compile group: 'org.eclipse.persistence', name: 'org.eclipse.persistence.moxy',
version: '2.7.3'
See also this great explanation
This example using MOXy also requires jaxb.properties
file containing information about JAXBContextFactory
(see here chapter 2.1):
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
Advantage of this seems to be:
Because you do not need to change any application code, you can easily switch between different JAXB implementations.
Answered By - pirho
Answer Checked By - Gilberto Lyons (JavaFixing Admin)