You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Quarkus构建GraalVM原生镜像遇getDeclaringClass0错误及解决

Quarkus构建GraalVM原生镜像时POI相关错误的解决办法

环境信息

  • Framework: Quarkus
  • JVM: OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08)
  • OS: macOS Monterey, Chip: M2

触发错误的命令

mvn clean package -Pnative -DskipTests

错误详情

构建原生镜像时出现以下错误:

Error: Discovered a type for which getDeclaringClass0 cannot be called:
org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STConformanceClass$Enum. This error is reported at image build time because class org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STConformanceClass$Enum is registered for linking at image build time by command line
com.oracle.svm.core.util.UserError$UserException: Discovered a type for which getDeclaringClass0 cannot be called: org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STConformanceClass$Enum. This error is reported at image build time because class org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STConformanceClass$Enum is registered for linking at image build time by command line
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.UserError.abort(UserError.java:85)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FallbackFeature.reportAsFallback(FallbackFeature.java:248)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:776)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:578)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Discovered a type for which getDeclaringClass0 cannot be called: org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STConformanceClass$Enum. This error is reported at image build time because class org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STConformanceClass$Enum is registered for linking at image build time by command line
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.SVMHost.handleLinkageError(SVMHost.java:444)

问题分析

无法找到org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STConformanceClass类的实现,已知找到该类的实现并添加到pom及reflect-config.json中可解决此问题。

尝试的解决方法

  • 在pom中添加参数:--initialize-at-run-time=org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STConformanceClass
  • 在reflect-config.json中加入以下配置:
{
    "name": "org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STConformanceClass"
}

最终解决办法

通过替换POI依赖成功解决问题,具体依赖配置如下:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.2.3</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-lite</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml-full</artifactId>
    <version>5.2.3</version>
</dependency>

内容的提问来源于stack exchange,提问作者Mahdi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 18:20:42