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

huangapple go评论68阅读模式
英文:

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

问题

I'm building a microservice using Quarkus.
我正在使用 Quarkus 构建微服务。

I'm using JAXB to marshal XML files that the service receives via a REST API endpoint.
我正在使用 JAXB 来将服务通过 REST API 端点接收的 XML 文件进行编组。

My native build always throws the following error: java.util.ServiceConfigurationError: jakarta.xml.bind.JAXBContextFactory: Provider org.glassfish.jaxb.runtime.v2.JAXBContextFactory not found.
我的本地构建始终抛出以下错误:java.util.ServiceConfigurationError: jakarta.xml.bind.JAXBContextFactory: Provider org.glassfish.jaxb.runtime.v2.JAXBContextFactory 未找到

The error only occurs with the native build, the JVM build works fine.
这个错误仅在本地构建中出现,JVM 构建正常运行。

In build.gradle, I added io.quarkus:quarkus-resteasy-reactive-jaxb and org.glassfish.jaxb:
build.gradle 中,我添加了 io.quarkus:quarkus-resteasy-reactive-jaxborg.glassfish.jaxb

英文:

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"
}

答案1

得分: 1

  • 将 org.apache.camel.quarkus:camel-quarkus-xml-jaxb 添加为 build.gradle 依赖项。
  • 在 src/main/resources 文件夹中创建 reflection-config.json 文件,并包含以下内容:
[
  {
    "name": "org.glassfish.jaxb.runtime.v2.JAXBContextFactory",
    "allDeclaredConstructors": true
  }
]
  • 在 application.properties 中引用反射配置,如下所示:
quarkus.native.additional-build-args=-H:ReflectionConfigurationFiles=reflection-config.json
英文:

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

huangapple
  • 本文由 发表于 2023年5月10日 21:53:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76219270.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定