Pentaho / POI引发InvocationTargetException

时间:2019-04-22 08:12:55

标签: pentaho java-11 fontconfig

我正在尝试将我的所有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.

1 个答案:

答案 0 :(得分:0)

解决了两件事(使用docker实现):

  1. 添加配置变量:

    这是让JDK知道libfontconfig.so的位置在哪里

  

ENV LD_LIBRARY_PATH =“ $ {LD_LIBRARY_PATH}:/ usr / lib /:/ usr / lib64 /”

  1. 将默认文件添加到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分钟后,问题消失。

解决方案:

  1. 添加额外的TTF文件(对我来说是calibri.ttf)并复制到/ usr / share / fonts / TTF

  2. 执行以下命令:fc-cache -fv这可以确保fontconfig立即加载字体。

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