Autosize needs a font to figure out the width of the columns. There are some openjdk builds (AdoptOpenJDK for example) that do not ship with embedded lucinda fonts due to license issues and so java looks to the OS.
https://github.com/AdoptOpenJDK/openjdk-build/issues/682 On windows, there are fonts installed but on linux, you may need to install some... assuming CentOS, you might try something like ... yum install -y dejavu-sans-fonts dejavu-serif-fonts dejavu-sans-mono-fonts From: Andreas Reichel <[email protected]> Sent: Wednesday, February 19, 2020 1:49 AM To: [email protected] Subject: Re: Exception when moving from windows to linux [EXTERNAL] Additionally you might need to load the needed Fonts manually, when the server is headless and no FontConfig stuff is used/provided. If you want to provide the Fonts as resources in your class path, something like the snipet below might work: /home/are/Documents/src/SwingUI/src/com/manticore/swingui/SwingUI.java 100 public static void prepareFonts() { 101 try { 102 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 103 for (String res : fontResources) 104 ge.registerFont( 105 Font.createFont(Font.TRUETYPE_FONT, ClassLoader.getSystemResourceAsStream(res))); 106 107 // for (String s:ge.getAvailableFontFamilyNames()) 108 // System.out.println(s); 109 SMALL_MANTICORE_FONT = new Font("Roboto", Font.PLAIN, 12); 110 SMALL_MANTICORE_FONT_BOLD = new Font("Roboto", Font.BOLD, 12); 111 SMALL_MANTICORE_FONT_ITALIC = new Font("Roboto", Font.ITALIC, 12); 112 SMALL_MANTICORE_FONT_BOLDITALIC = new Font("Roboto", Font.BOLD | Font.ITALIC, 12); 113 114 MONO_MANTICORE_FONT = new Font("Roboto Mono", Font.PLAIN, 11); 115 MONO_MANTICORE_FONT_BOLD = new Font("Roboto Mono", Font.BOLD, 11); 116 MONO_MANTICORE_FONT_ITALIC = new Font("Roboto Mono", Font.ITALIC, 11); 117 MONO_MANTICORE_FONT_BOLDITALIC = new Font("Roboto Mono", Font.BOLD | Font.ITALIC, 11); 118 119 MEDIUM_MANTICORE_FONT = new Font("Roboto Medium", Font.PLAIN, 16); 120 BIG_MANTICORE_FONT = MEDIUM_MANTICORE_FONT.deriveFont(Font.PLAIN, 22); 121 122 } catch (FontFormatException ex) { 123 Logger.getLogger(SwingUI.class.getName()).log(Level.SEVERE, null, ex); 124 } catch (IOException ex) { 125 Logger.getLogger(SwingUI.class.getName()).log(Level.SEVERE, null, ex); 126 } 127 } On Wed, 2020-02-19 at 14:43 +0700, Andreas Reichel wrote: > Dear Matthias, > please try to install the X Virtual Frame Buffer (XVFB) and start > thatin the background, before starting the Java VM.As far as I know, > the Java VM needs a Graphic Device for all the AWTbased operations, > inclduing Fonts. > Best regardsAndreas > On Wed, 2020-02-19 at 08:40 +0100, Matthias Pfeifer wrote: > > Hi there, > > I am using apache poi 4.1.0 and i have some code that should create > > aWorkbook, create a sheet, put some data in it and store it into > > filesystem. My code runs fine on my windows box but throws > > exception whenmoving to linux (please no jokes about linux box > > refusing code due to badsmell, i had some of those already ;-) ). > > I am running into this exception when I am calling > > autoSizeColumn(...) on aXSSFSheet (in a XSSFWorkbook)... > > Here's my stacktrace: > > java.lang.InternalError: > > java.lang.reflect.InvocationTargetException at > > sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86)~[?:?] > > at java.security.AccessController.doPrivileged(Native > > Method) > > ~[?:?] atsun.font.FontManagerFactory.getInstance(FontManager > > http://Factory.java:74<http://Factory.java:74>) ~[?:?] at > > java.awt.Font.getFont2D(Font.java:497) ~[?:?] at > > java.awt.Font.canDisplayUpTo(Font.java:2246) ~[?:?] at > > java.awt.font.TextLayout.singleFont(TextLayout.java:469) > > ~[?:?] at > > java.awt.font.TextLayout.<init>(http://TextLayout.java:530<http://TextLayout.java:530>) > > ~[?:?] atorg.apache.poi.ss.util.SheetUtil.getDefaultCharWidt > > h(http://SheetUtil.java:273<http://SheetUtil.java:273>)~[poi- > > 4.1.0.jar:4.1.0] atorg.apache.poi.ss.util.SheetUtil.getColum > > nWidth(http://SheetUtil.java:248<http://SheetUtil.java:248>)~[poi- > > 4.1.0.jar:4.1.0] atorg.apache.poi.ss.util.SheetUtil.getColum > > nWidth(http://SheetUtil.java:233<http://SheetUtil.java:233>)~[poi- > > 4.1.0.jar:4.1.0] atorg.apache.poi.xssf.usermodel.XSSFSheet.a > > utoSizeColumn(http://XSSFSheet.java:549<http://XSSFSheet.java:549>)~[poi-ooxml- > > 4.1.0.jar:4.1.0] atorg.apache.poi.xssf.usermodel.XSSFSheet.a > > utoSizeColumn(http://XSSFSheet.java:531<http://XSSFSheet.java:531>)~[poi-ooxml- > > 4.1.0.jar:4.1.0] at > > my.package.rest.api.exportTable(ExportTable.java:181)~[classes/:?] > > <SNIP> > > Caused by: > > java.lang.reflect.InvocationTargetException atjdk.internal.r > > eflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod) > > ~[?:?] atjdk.internal.reflect.NativeConstructorAccessorImpl. > > newInstance(http://NativeConstructorAccessorImpl.java:62<http://NativeConstructorAccessorImpl.java:62>)~[?:?] > > atj > > dk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(D > > http://elegatingConstructorAccessorImpl.java:45<http://elegatingConstructorAccessorImpl.java:45>)~[?:?] > > at > > java.lang.reflect.Constructor.newInstance(Constructor.java:490)~[?: > > ?] at > > sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84)~[?:?] > > ... 63 more > > Caused by: > > java.lang.NullPointerException atsun.awt.FontConfiguration.g > > etVersion(http://FontConfiguration.java:1262<http://FontConfiguration.java:1262>) > > ~[?:?] atsun.awt.FontConfiguration.readFontConfigFile(FontCo > > http://nfiguration.java:225<http://nfiguration.java:225>)~[?:?] at > > sun.awt.FontConfiguration.init(FontConfiguration.java:107) > > ~[?:?] atsun.awt.X11FontManager.createFontConfiguration(X11F > > http://ontManager.java:719<http://ontManager.java:719>)~[?:?] at > > sun.font.SunFontManager$2.run(SunFontManager.java:367) > > ~[?:?] at java.security.AccessController.doPrivileged(Native > > Method) ~[?:?] at > > sun.font.SunFontManager.<init>(http://SunFontManager.java:312<http://SunFontManager.java:312>) > > ~[?:?] at > > sun.awt.FcFontManager.<init>(http://FcFontManager.java:35<http://FcFontManager.java:35>) > > ~[?:?] at > > sun.awt.X11FontManager.<init>(http://X11FontManager.java:56<http://X11FontManager.java:56>) > > ~[?:?] atjdk.internal.reflect.NativeConstructorAccessorImpl. > > newInstance0(NativeMethod) > > ~[?:?] atjdk.internal.reflect.NativeConstructorAccessorImpl. > > newInstance(http://NativeConstructorAccessorImpl.java:62<http://NativeConstructorAccessorImpl.java:62>)~[?:?] > > atj > > dk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(D > > http://elegatingConstructorAccessorImpl.java:45<http://elegatingConstructorAccessorImpl.java:45>)~[?:?] > > at > > java.lang.reflect.Constructor.newInstance(Constructor.java:490)~[?: > > ?] at > > sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84)~[?:?] > > ... 63 more > > > > I got the impression that the issue might deal with font > > availability onlinux. The host system has no x11 installed for > > example. > > How would I be able to have my code running on the linux box? Is > > the choiceof Workbook important? Would it help to use a > > HSSFWorkbook instead? > > > > > > Thanks in advance > > > > Matthias.
