pas de fontmanager en java.bibliothèque.chemin


Le code suivant fonctionne très bien sur mon bureau:

        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setFont(new Font("SansSerif", Font.BOLD, 18));

        Graphics2D graphics = (Graphics2D) g;
        graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        graphics.drawString(s, 5, 20);

Cependant, lorsque j'exécute ce code sur mon serveur (openjdk fonctionnant sous linux alpine dans un conteneur Docker), il échoue avec l'erreur suivante:

java.lang.UnsatisfiedLinkError: no fontmanager in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at sun.font.FontManagerNativeLibrary$1.run(FontManagerNativeLibrary.java:61)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerNativeLibrary.<clinit>(FontManagerNativeLibrary.java:32)
at sun.font.SunFontManager$1.run(SunFontManager.java:339)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.SunFontManager.<clinit>(SunFontManager.java:335)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:82)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.awt.Font.getFont2D(Font.java:491)
at java.awt.Font.access$000(Font.java:224)
at java.awt.Font$FontAccessImpl.getFont2D(Font.java:228)
at sun.font.FontUtilities.getFont2D(FontUtilities.java:180)
at sun.java2d.SunGraphics2D.checkFontInfo(SunGraphics2D.java:669)
at sun.java2d.SunGraphics2D.getFontInfo(SunGraphics2D.java:830)
at sun.java2d.pipe.GlyphListPipe.drawString(GlyphListPipe.java:50)
at sun.java2d.pipe.ValidatePipe.drawString(ValidatePipe.java:165)
at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2928)

Java -version (sur mon serveur) donne:

openjdk version "1.8.0_77-internal"
OpenJDK Runtime Environment (build 1.8.0_77-internal-alpine-r0-b03)
OpenJDK 64-Bit Server VM (build 25.77-b03, mixed mode)

J'ai cherché des bibliothèques awt et elles peuvent être trouvées ici:

/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/libawt_headless.so
/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/libawt.so
Author: benjamin.d, 2016-05-16

1 answers

J'ai rencontré exactement le même problème en exécutant Alpine Linux 3.4. J'ai résolu le problème en suivant les instructions dans ce problème github :

  1. Installez le JRE avec le support de l'interface GRAPHIQUE, c'est-à-dire openjdk8-jre au lieu de openjdk8-jre-head
  2. Installer les paquets fontconfig et ttf-dejavu

La ligne d'exécution dans mon Dockerfile ressemble à:

RUN apk add openjdk8-jre fontconfig ttf-dejavu

Après cela, le JDK a pu charger automatiquement les polices par défaut, et l'exception a disparu.

 3
Author: Jason Hoetger, 2016-10-04 20:40:10