英文:
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-jaxb
和 org.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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论