NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager
If you are using the docker 'slim images' of openjdk, the image no longer includes the packages 'fontconfig', and 'libfreetype6'.
Check the difference in docker file of openjdk:11-slim and the docker file of openjdk:8-slim.
You could either pick another docker image (e.g. openjdk:11-windowsservercore
), or install the packages yourself in your docker file:
RUN apt-get update; apt-get install -y fontconfig libfreetype6
Problem occurs when you use openjdk docker image in alpine version for example :
adoptopenjdk/openjdk11:jre-11.0.11_9-alpine
.
You need chenge image to full version: adoptopenjdk/openjdk11:jre-11.0.11_9
The underlying issues is something else
I just created a simple class which does class loading of X11FontManager and when I ran it complained
unable to link "libfreetype6"
once I installed it using
apt-get install libfreetype6
started throwing could not link "libfontconfig1.so"
apt-get install libfontconfig1
that fixed the issue
Read this and understood few things https://medium.com/azulsystems/using-jlink-to-build-java-runtimes-for-non-modular-applications-9568c5e70ef4