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
> > 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>(TextLayout.java:530)
> > ~[?:?] atorg.apache.poi.ss.util.SheetUtil.getDefaultCharWidt
> > h(SheetUtil.java:273)~[poi-
> > 4.1.0.jar:4.1.0] atorg.apache.poi.ss.util.SheetUtil.getColum
> > nWidth(SheetUtil.java:248)~[poi-
> > 4.1.0.jar:4.1.0] atorg.apache.poi.ss.util.SheetUtil.getColum
> > nWidth(SheetUtil.java:233)~[poi-
> > 4.1.0.jar:4.1.0] atorg.apache.poi.xssf.usermodel.XSSFSheet.a
> > utoSizeColumn(XSSFSheet.java:549)~[poi-ooxml-
> > 4.1.0.jar:4.1.0] atorg.apache.poi.xssf.usermodel.XSSFSheet.a
> > utoSizeColumn(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(NativeConstructorAccessorImpl.java:62)~[?:?] atj
> > dk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(D
> > 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(FontConfiguration.java:1262)
> > ~[?:?] atsun.awt.FontConfiguration.readFontConfigFile(FontCo
> > nfiguration.java:225)~[?:?] at
> > sun.awt.FontConfiguration.init(FontConfiguration.java:107)
> > ~[?:?] atsun.awt.X11FontManager.createFontConfiguration(X11F
> > ontManager.java:719)~[?:?] at
> > sun.font.SunFontManager$2.run(SunFontManager.java:367)
> > ~[?:?] at java.security.AccessController.doPrivileged(Native
> > Method) ~[?:?] at
> > sun.font.SunFontManager.<init>(SunFontManager.java:312)
> > ~[?:?] at
> > sun.awt.FcFontManager.<init>(FcFontManager.java:35)
> > ~[?:?] at
> > sun.awt.X11FontManager.<init>(X11FontManager.java:56)
> > ~[?:?] atjdk.internal.reflect.NativeConstructorAccessorImpl.
> > newInstance0(NativeMethod)
> > ~[?:?] atjdk.internal.reflect.NativeConstructorAccessorImpl.
> > newInstance(NativeConstructorAccessorImpl.java:62)~[?:?] atj
> > dk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(D
> > 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.