Kotlin Quarkus GraalVM Native Image 中的类转换异常

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

Class Cast Exception in Kotlin Quarkus GraalVM Native Image

问题

已解决: @geoand在评论中提到了io.quarkiverse.poi:quarkus-poi扩展,解决了我的所有问题!请参阅:https://github.com/quarkiverse/quarkus-poi 和:https://mvnrepository.com/artifact/io.quarkiverse.poi/quarkus-poi/2.0.2

我正在尝试创建一个响应Excel文件的微服务。如果我运行quarkusDev,一切正常。但是在构建原生镜像之后,我遇到了这个错误:

这是用于创建xlsx的函数:

这些是依赖项:

使用:
Quarkus v3.1.2.Final
构建命令:
./gradlew clean build -Dquarkus.package.type=native -Dquarkus.native.container-build=true
镜像:
quay.io/quarkus/ubi-quarkus-mandrel-builder-image:22.3-java17

我还尝试过在构建时构建“有问题”的依赖项(作为应用程序属性中的附加构建参数),但没有效果

英文:

SOLVED: @geoand mentioned the io.quarkiverse.poi:quarkus-poi extension in the comments, which solved all my problems! See: https://github.com/quarkiverse/quarkus-poi
and: https://mvnrepository.com/artifact/io.quarkiverse.poi/quarkus-poi/2.0.2

I’m trying to create a microservices that responds with an excel file. If I run quarkusDev everything works fine. But after building the native image, I’m getting this error:

    2023-07-06 15:54:30,451 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP    Request to /api/excel failed, error id: 0694d603-5557-4806-bd87-3cd93c6730d9-2:   java.lang.ClassCastException: org.apache.xmlbeans.impl.values.XmlComplexContentImpl cannot be cast   to org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument
        at org.apache.poi.xssf.model.ThemesTable.readFrom(ThemesTable.java:119)
        at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:87)
        at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:61)
        at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:661)
        at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:165)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:260)
        at   org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(XSSFWorkbookFactory.java:118)
        at org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.create(XSSFWorkbookFactory.java:98)
        at org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.create(XSSFWorkbookFactory.java:36)
        at org.apache.poi.ss.usermodel.WorkbookFactory.lambda$create$2(WorkbookFactory.java:224)
        at org.apache.poi.ss.usermodel.WorkbookFactory.wp(WorkbookFactory.java:329)
        at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:224)
        at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:185)
        at com.test.services.ExcelService.createExcel(ExcelService.kt:13)
        at com.test.services.ExcelService_ClientProxy.createExcel(Unknown Source)
        at com.test.services.ExcelFileService.submitDTO(ExcelFileService.kt:39)
        at com.test.services.ExcelFileService_ClientProxy.submitDTO(Unknown Source)
        at com.test.resources.ExcelFileResource.DTO(ExcelFileResource.kt:79)
        at com.test.resources.ExcelFileResource_Subclass.DTO$$superforward(Unknown Source)
        at com.test.resources.ExcelFileResource_Subclass$$function$$2.apply(Unknown Source)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:73)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:62)
        at io.quarkus.hibernate.validator.runtime.interceptor.AbstractMethodValidationInterceptor.validateMethodInvocation(AbstractMethodValidationInterceptor.java:71)
        at io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyReactiveEndPointValidationInterceptor.validateMethodInvocation(ResteasyReactiveEndPointValidationInterceptor.java:21)
        at   io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyReactiveEndPointValidationInterceptor_Bean.intercept(Unknown Source)
        at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:30)
        at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:27)
        at com.test.resources.ExcelFileResource_Subclass.DTO(Unknown Source)
        at com.test.resources.ExcelFileResource$quarkusrestinvoker$DTO_d3f979f0d6dd3140a96a1564a9bba43107110fd0.invoke(Unknown Source)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at io.quarkus.resteasy.reactive.server.runtime.Q`your text`uarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:145)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:576)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base@17.0.7/java.lang.Thread.run(Thread.java:833)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:203)

This is the function for the xlsx creation:

        fun createExcel(_: List<Input>): ByteArrayOutputStream {
            val inputStream = this::class.java.classLoader.getResourceAsStream("excel-templates/test.xlsx")
            val workbook = WorkbookFactory.create(inputStream)
    
            val sheet = workbook.getSheetAt(0)
            val row = sheet.getRow(0)
            val cell = row.createCell(1)
            cell.setCellValue("new entry")
    
            val baos = ByteArrayOutputStream()
            workbook.write(baos)
            baos.close()
    
            return baos
        }

These are the dependencies:

    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("io.quarkus:quarkus-kotlin")
    implementation("io.quarkus:quarkus-arc")
    implementation("io.quarkus:quarkus-resteasy-reactive-jackson")
    implementation("io.quarkus:quarkus-rest-client-reactive-jackson")
    implementation("io.quarkus:quarkus-smallrye-openapi")
    implementation("io.quarkus:quarkus-hibernate-validator")
    //POI
    implementation("org.apache.poi:poi:5.2.3")
    implementation("org.apache.poi:poi-ooxml:5.2.3")
    implementation("org.apache.poi:poi-ooxml-full:5.2.3")
    //Log4j
    implementation("org.apache.logging.log4j:log4j-api:2.20.0")
    implementation("org.apache.logging.log4j:log4j-core:2.20.0")

Using:
Quarkus v3.1.2.Final
Build with:
./gradlew clean build -Dquarkus.package.type=native -Dquarkus.native.container-build=true
Image:
quay.io/quarkus/ubi-quarkus-mandrel-builder-image:22.3-java17

I’ve also tried to build the "problematic" dependencies at build time (as a additional build arg in the application.properites) but with no effect

答案1

得分: 0

你很可能需要添加 Apache POI 扩展,它会执行一些操作以使 POI 在本机模式下工作。

英文:

You most likely need to add the Apache POI extension which does a few things in order to make POI work on native mode.

huangapple
  • 本文由 发表于 2023年7月7日 00:20:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76630787.html
匿名

发表评论

匿名网友

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

确定