I am using a custom Java 11 runtime on custom linux hardware, the Java runtime was not built my me. But I have a problem my application requires access to a font and the runtime is not configured with any so I get this stacktrace
Exception in thread "main" 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.getFamily(Font.java:1410)
at java.desktop/java.awt.Font.getFamily_NoClientCode(Font.java:1384)
at java.desktop/java.awt.Font.getFamily(Font.java:1376)
at java.desktop/java.awt.Font.toString(Font.java:1869)
at java.base/java.lang.String.valueOf(String.java:2951)
at java.base/java.io.PrintStream.println(PrintStream.java:897)
at Fonts.main(Fonts.java:7)
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)
... 10 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)
I can provide some fonts and I have worked out I need to create a fontconfig.properties and put i into the Java runtimes lib folder, but I am struggling to understand what I need to put into fontconfig.properties.
Can someone give me an example of how to specify a minimal set of fonts in fontconfig.properties on linux to prevent the exception occurring.
More specificially, I have a set of truetype fonts that I have put into a fonts folder within the lib folder so how do I use this set as a set of fonts available to Java
- LucidaBrightDemiItalic.ttf
- LucidaBrightRegular.ttf
- LucidaSansRegular.ttf
- LucidaTypewriterRegular.ttf
- LucidaBrightDemiBold.ttf
- LucidaBrightItalic.ttf
- LucidaSansDemiBold.ttf
- LucidaTypewriterBold.ttf
If I create an empty fontconfig.properties file then the first exception changes to
Caused by: java.lang.NullPointerException
at java.desktop/sun.awt.FontConfiguration.getInitELC(FontConfiguration.java:465)
at java.desktop/sun.awt.FontConfiguration.initFontConfig(FontConfiguration.java:441)
at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:108)
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)
so this shows Java runtime is at least finding the (empty) fontconfig.properties file so if I can configure it correctly this should work.
I tried to create a very minimal fontconfig.properties file with one file but it didnt work.
version=1
allfonts.plain.latin-1=-monotype-times new roman-medium-r-normal--*-%d-*-*-p-*-iso10646-1
filename.-monotype-times new roman-medium-r-normal--*-%d-*-*-p-*-iso10646-1=/mnt/app/opt/SongKong/songkong/jre/lib/fonts/ipag.ttf
awtfontpath.latin-1=/mnt/app/opt/SongKong/songkong/jre/lib/fonts