简体   繁体   English

java.library.path 中没有字体管理器

[英]no fontmanager in java.library.path

The following code works just fine on my desktop:以下代码在我的桌面上运行良好:

        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);

However, when I run this code on my server (openjdk running on linux alpine within a Docker container), it fails with the following error:但是,当我在我的服务器上运行此代码(在 Docker 容器内的 linux alpine 上运行的 openjdk)时,它失败并显示以下错误:

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 (on my server) gives: java -version(在我的服务器上)给出:

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)

I searched for awt libs and they could be found here:我搜索了 awt 库,它们可以在这里找到:

/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

I ran into this exact same problem running Alpine Linux 3.4.我在运行 Alpine Linux 3.4 时遇到了完全相同的问题。 I solved the problem by following the directions in this github issue :我按照这个 github 问题中的说明解决了这个问题

  1. Install the JRE with GUI support, ie openjdk8-jre instead of openjdk8-jre-head安装支持 GUI 的 JRE,即openjdk8-jre而不是openjdk8-jre-head
  2. Install the fontconfig and ttf-dejavu packages安装fontconfigttf-dejavu

The RUN line in my Dockerfile looks like:我的 Dockerfile 中的 RUN 行如下所示:

RUN apk add openjdk8-jre fontconfig ttf-dejavu

After this, the JDK was able to load the default fonts automatically, and the exception went away.此后,JDK 能够自动加载默认字体,异常消失了。

I ran into the same issue with my docker image for which I used Java 11 app base which does not have GUI libraries installed.我的 docker 镜像遇到了同样的问题,我使用了没有安装 GUI 库的 Java 11 应用程序库。 I got the error like no font manager and the cause for that error is -> it is failing to read/create font using awt library.我收到了类似没有字体管理器的错误,该错误的原因是 -> 无法使用 awt 库读取/创建字体。

When used the java stretch image with GUI support the error gone away.当使用带有 GUI 支持的 java 拉伸图像时,错误消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM