【背景】
操作系统:CentOS 7
项目:使用JDK11,EasyExcel 3.2.1导出Excel
【操作】web端导出Excel,日志提示异常,详细如下:
Caused by: java.lang.InternalError: java.lang.reflect.InvocationTargetExceptionat 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:2250)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.xssf.streaming.AutoSizeColumnTracker.<init>(AutoSizeColumnTracker.java:117)at org.apache.poi.xssf.streaming.SXSSFSheet.<init>(SXSSFSheet.java:82)at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:684)at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:705)at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:88)at com.alibaba.excel.util.WorkBookUtil.createSheet(WorkBookUtil.java:84)at com.alibaba.excel.context.WriteContextImpl.createSheet(WriteContextImpl.java:223)at com.alibaba.excel.context.WriteContextImpl.initSheet(WriteContextImpl.java:203)at com.alibaba.excel.context.WriteContextImpl.currentSheet(WriteContextImpl.java:135)at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:54)... 139 common frames omitted Caused by: java.lang.reflect.InvocationTargetException: nullat 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)... 156 common frames omitted Caused by: java.lang.NullPointerException: nullat 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:377)at java.base/java.security.AccessController.doPrivileged(Native Method)at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:322)at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35)at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56)
【解决措施】
解决措施:
1、从本地window中取字体,C:\Windows\Fonts,并压缩成zip
2、上传到服务器上/usr/local/share/fonts,使生效
# fc-list :lang=zh
# fc-cache
3、重启java服务