Pentaho/POI throws InvocationTargetException

℡╲_俬逩灬. 提交于 2019-12-11 10:59:54

问题


I am trying to upgrade all my java application to openJDK11 ( from Oracle 8 ). and I notice one problem in my reporting server which use Pentaho.

It seems that the Excel autosize feature requires libfontconfig.so in openJDK11,

however I can find the module at /usr/lib64/libfontconfig.so.

Any way to solve this?

    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

Update :

after putting '-Dsun.java2d.debugfonts=true' I got this logs :

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:


Solved by doing 2 things ( implemented using docker ) :

  1. add configuration variables :

    this is needed to let JDK know where is the location of libfontconfig.so

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

  1. add default files to JDK/lib folder:

    This is needed because openjdk does not have it by default. the below files are coming from 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

Update : the above solution works, but sometimes after the redhat linux loaded, it seems not able to find the font and giving the "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')". After 10-30 mins, the issue disappears.

Solution for this :

  1. Adding extra TTF files ( for me it was calibri.ttf ) and copied to /usr/share/fonts/TTF

  2. execute this command : fc-cache -fv This to ensure the font loaded immediately by the fontconfig.

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


来源:https://stackoverflow.com/questions/55791235/pentaho-poi-throws-invocationtargetexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!