Использование Apache POI с собственным образом GraalVM — ClassCastException от XMLBeans

Получение следующей ошибки при создании листа Excel с использованием Apache POI.

Код выполняется в eclipse, но при преобразовании в собственный образ GraalVM выдает следующую ошибку.

Exception in thread "main" java.lang.ClassCastException: org.apache.xmlbeans.impl.values.XmlComplexContentImpl cannot be cast to org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook
        at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.newInstance(Unknown Source)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(XSSFWorkbook.java:460)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:263)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:257)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:245)
        at POITest.test.ApachePOIExcelWrite.main(ApachePOIExcelWrite.java:21)

person Mohit Ochani    schedule 04.12.2019    source источник
comment
Похоже на ошибку в процессе сборки. Как вы компилируете/создаете/упаковываете свою программу?   -  person Gagravarr    schedule 04.12.2019
comment
я преобразовываю банку в собственное изображение с помощью graalvm, при создании листа Excel я получаю указанную выше ошибку.   -  person Mohit Ochani    schedule 04.12.2019
comment
Звучит как ошибка graalvm, если она работает на обычной JVM....   -  person Gagravarr    schedule 04.12.2019
comment
Как у вас дела со сборкой GraalVM? Какие ReflectionConfigurationFiles значения вы передаете?   -  person Gagravarr    schedule 04.12.2019
comment
Ниже приведен файл конфигурации отражения: ссылка.   -  person Mohit Ochani    schedule 04.12.2019
comment
Можете ли вы предоставить пример проекта, который воспроизводит проблему, будет предпочтительно, если вы укажете версии для Java и GraalVM.   -  person Taha BASRI    schedule 25.12.2019


Ответы (1)


Вы должны:

  1. Запустить инспекционную сборку
  2. Метод вызова, который создает это исключение, для создания правильного Reflect-config.json
  3. Выберите классы, которые относятся к Apache POI, и скопируйте их в свой Reflect-config.json.
  4. Поместите в application.properties:
    #P2#

например, это мои классы, которые я добавил в свой Reflect-config.json, чтобы улучшить это исключение в собственной сборке:

 {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorkbookImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorkbookPrImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorksheetImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTXfImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STBorderIdImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STCellRefImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STCellStyleXfIdImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STCellTypeImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STFillIdImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STFontIdImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STFontSchemeImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STNumFmtIdImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STPatternTypeImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STRefImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STXstringImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.SstDocumentImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.StyleSheetDocumentImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.officeDocument.x2006.customProperties.impl.CTPropertiesImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.officeDocument.x2006.customProperties.impl.PropertiesDocumentImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.impl.CTPropertiesImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.impl.PropertiesDocumentImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.officeDocument.x2006.relationships.impl.STRelationshipIdImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType$Enum",
    "fields": [
      {
        "name": "table"
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme$Enum"
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType$Enum"
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTBookViewImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTBookViewsImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTBooleanPropertyImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTBorderImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTBorderPrImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTBordersImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTCellImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTCellStyleXfsImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTCellXfsImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTColImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTColorImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTColsImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFillImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFillsImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontNameImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontSchemeImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontSizeImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontsImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTIntPropertyImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTNumFmtImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTNumFmtsImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTPageMarginsImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTPatternFillImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTRowImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTRstImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTSheetDataImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTSheetDimensionImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTSheetFormatPrImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTSheetImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTSheetViewImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTSheetViewsImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTSheetsImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTSstImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  },
  {
    "name": "org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTStylesheetImpl",
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": [
          "org.apache.xmlbeans.SchemaType"
        ]
      }
    ]
  }
person Kosta    schedule 10.04.2020