gpt4 book ai didi

Pentaho/POI 抛出 InvocationTargetException

转载 作者:行者123 更新时间:2023-12-03 23:52:17 31 4
gpt4 key购买 nike

我正在尝试将我的所有 java 应用程序升级到 openJDK11(来自 Oracle 8)。
我注意到我的报告服务器中使用 Pentaho 的一个问题。

看来 Excel 自动调整大小功能需要 openJDK11 中的 libfontconfig.so,

但是我可以在/usr/lib64/libfontconfig.so 找到该模块。
enter image description here

有什么办法可以解决这个问题?

    2019/04/18 19:22:38 - GetReportJSon.0 - Finished reading query, closing connection.
2019/04/18 19:22:38 - GetReportJSon.0 - Finished processing (I=1, O=0, R=0, W=2, U=0, E=0)
java.lang.InternalError: java.lang.reflect.InvocationTargetException
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.desktop/java.awt.Font.getFont2D(Font.java:497)
at java.desktop/java.awt.Font.canDisplayUpTo(Font.java:2246)
at java.desktop/java.awt.font.TextLayout.singleFont(TextLayout.java:469)
at java.desktop/java.awt.font.TextLayout.<init>(TextLayout.java:530)
at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273)
at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:248)
at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:233)
at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:551)
at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:533)
at org.pentaho.di.trans.steps.excelwriter.ExcelWriterStep.closeOutputFile(ExcelWriterStep.java:244)
at org.pentaho.di.trans.steps.excelwriter.ExcelWriterStep.processRow(ExcelWriterStep.java:209)
at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84)
... 15 more
Caused by: java.lang.NullPointerException
at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262)
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225)
at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107)
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:719)
at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:367)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:312)
at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35)
at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56)
... 20 more
2019/04/18 19:22:40 - WriteReportAuthor.0 - ERROR (version 7.0.0.1-7, build 1 from 2016-12-07 21.19.28 by buildguy) : Unexpected error
2019/04/18 19:22:40 - WriteReportAuthor.0 - ERROR (version 7.0.0.1-7, build 1 from 2016-12-07 21.19.28 by buildguy) : java.lang.InternalError: java.lang.reflect.InvocationTargetException

更新 :

放置“-Dsun.java2d.debugfonts=true”后,我得到了以下日志:
Looking for text fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.RedHat.7.2.properties
Looking for binary fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.RedHat.7.2.bfc
Looking for text fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.RedHat.7.properties
Looking for binary fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.RedHat.7.bfc
Looking for text fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.RedHat.properties
Looking for binary fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.RedHat.bfc
Looking for text fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.7.2.properties
Looking for binary fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.7.2.bfc
Looking for text fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.7.properties
Looking for binary fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.7.bfc
Looking for text fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.properties
Looking for binary fontconfig file : /opt/jdk11/jdk-11.0.1/lib/fontconfig.bfc
Did not find a fontconfig file.

最佳答案

通过做两件事来解决(使用 docker 实现):

  • 添加配置变量:

    这需要让 JDK 知道 libfontconfig.so
  • 的位置在哪里

    ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/lib/:/usr/lib64/"


  • 将默认文件添加到 JDK/lib 文件夹:

    这是必需的,因为 openjdk 默认没有它。
    以下文件来自 Oracle JDK8

  • ADD ./src/main/resources/fontconfig.bfc /opt/jdk11/jdk-11.0.1/lib/fontconfig.bfc

    ADD ./src/main/resources/fontconfig.properties.src /opt/jdk11/jdk-11.0.1/lib/fontconfig.properties.src

    ADD ./src/main/resources/fonts /opt/jdk11/jdk-11.0.1/lib/fonts


    更新:上述解决方案有效,但有时在加载 redhat linux 后,似乎无法找到字体并给出 "java.lang.ClassCastException: class sun.font.CompositeFont cannot be cast to class sun.font.PhysicalFont (sun.font.CompositeFont and sun.font.PhysicalFont are in module java.desktop of loader 'bootstrap')" . 10-30 分钟后,问题消失。

    解决方案:
  • 添加额外的 TTF 文件(对我来说是 calibri.ttf )并复制到/usr/share/fonts/TTF
  • 执行这个命令: fc-cache -fv 这可以确保字体立即被 fontconfig 加载。

  • ADD ./src/main/resources/fonts/*.ttf /usr/share/fonts/TTF/
    RUN fc-cache -fv

    关于Pentaho/POI 抛出 InvocationTargetException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55791235/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com