Could not initialize class sun.awt.X11FontManager alpine java 17

Viewed 504

We're trying to run our java 8 application inside alpine_java-17 container. Everything compiles and works fine except one thing.

One functionality regarding excel doesn't work. In the logs I found:

Could not initialize class sun.awt.X11FontManager

Previously when we ran our app inside java8 container we didn't have this issue since we had command to install required packages:

RUN apt-get install -y fontconfig libfreetype6

But now since we have alpine 17 we changed the above command to

RUN apk add fontconfig
RUN apk add freetype

I tried to install libfreetype6 using RUN apk add libfreetype6 but docker returned me an error:

ERROR: unable to select packages:
  libfreetype6 (no such package):
    required by: world[libfreetype6]
Error response from daemon: The command '/bin/sh -c apk add libfreetype6' returned a non-zero code: 1

It seems like freetype is not the same as libfreetype6, but libfreetype6 is missing.

Can someone please help to understand the problem? Thanks in advance!

1 Answers

In my case, I encountered the problem in a docker image based on eclipse-temurin:17-jdk-alpine running a webapp that generates excel files using apache poi. After adding the packages fontconfig and ttf-dejavu as follows (it seems that freetype is a dependency of fontconfig and therefore does not have to be installed explicitly):

RUN apk add --no-cache fontconfig ttf-dejavu

not only the class FontText.java given here:

https://github.com/AdoptOpenJDK/openjdk-docker/issues/529#issuecomment-811687786

ran successfully, but also it was possible to generate excel files, which before resulted in the exception given in the question and in this exception:

...
Caused by: java.lang.UnsatisfiedLinkError: /opt/java/openjdk/lib/libfontmanager.so: Error loading shared library libfreetype.so.6: No such file or directory (needed by /opt/java/openjdk/lib/libfontmanager.so)
    at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
Related