Could not initialize class sun.awt.X11FontManager

2019-08-07 15:22发布

问题:

I'm getting this stack trace when using openjdk 8 with this docker image: openjdk:8-jre-alpine

java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager

at java.lang.Class.forName0(Native Method) [rt.jar:1.8.0_131]
at java.lang.Class.forName(Class.java:348) [rt.jar:1.8.0_131]
at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:82) [rt.jar:1.8.0_131]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0_131]
at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74) [rt.jar:1.8.0_131]
at java.awt.Font.getFont2D(Font.java:491) [rt.jar:1.8.0_131]
at java.awt.Font.getFontName(Font.java:1279) [rt.jar:1.8.0_131]
at java.awt.Font.getFontName(Font.java:1261) [rt.jar:1.8.0_131]

It works fine using the Oracle version

Following some directions to install the dejavu fonts from here: https://hub.docker.com/r/neduekwunife/openjdk8-jre-alpine-with-fontconfig/
I added the following line to my Dockerfile:

RUN apk add --update ttf-dejavu && rm -rf /var/cache/apk/*

which now gives me the following error:

java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/libfontmanager.so: Error relocating /usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/libfontmanager.so: AWTFontDefaultChar: symbol not found

回答1:

I was able to get this to work by reverting to an older version of openjdk container. Here is the FROM statement in my Dockerfile:

FROM openjdk:8u121-jre-alpine

which replaced this:

FROM openjdk:8-jre-alpine

which is currently equivalent to update 131.

There is a bug for this documented here: https://bugs.alpinelinux.org/issues/7372