Search code examples
gradlejaxbquarkusquarkus-native

JAXB not working with Quarkus native build - 'org.glassfish.jaxb.runtime.v2.JAXBContextFactory not found'


I'm building a microservice using Quarkus. I'm using JAXB to marschall XML files that the service receives via a REST API endpoint.

My native build always throws the following error: java.util.ServiceConfigurationError: jakarta.xml.bind.JAXBContextFactory: Provider org.glassfish.jaxb.runtime.v2.JAXBContextFactory not found. The error only occurs with the native build, the JVM build works fine.

In build.gradle, I added io.quarkus:quarkus-resteasy-reactive-jaxb and org.glassfish.jaxb:

dependencies {
    implementation 'io.quarkus:quarkus-resteasy-reactive-jaxb'
     .
     .
     .
    jaxb "org.glassfish.jaxb:jaxb-xjc:4.0.1"
    jaxb "org.glassfish.jaxb:jaxb-runtime:4.0.1"
}

Solution

  • I had the same issue. The following fixed it for me:

    • Add org.apache.camel.quarkus:camel-quarkus-xml-jaxb as dependency to your build.gradle.

    • Create a reflection-config.json (in folder src/main/resources) with the below content:

        [
          {
            "name": "org.glassfish.jaxb.runtime.v2.JAXBContextFactory",
            "allDeclaredConstructors" : true
          }
        ]
    
    • Reference the reflection config in your application.properties like so:
        quarkus.native.additional-build-args=-H:ReflectionConfigurationFiles=reflection-config.json