简体   繁体   English

NoClassDefFoundError:无法初始化类 sun.awt.X11FontManager

[英]NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager

when we migrated from Oracle JDK-8 to Open JDK-11, Apache POI excel generation has issues当我们从 Oracle JDK-8 迁移到 Open JDK-11 时,Apache POI excel 生成有问题

tried already -Djava.awt.headless=true已经尝试过-Djava.awt.headless=true

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1053)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:901)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)```

If you are using the docker 'slim images' of openjdk, the image no longer includes the packages 'fontconfig', and 'libfreetype6'.如果您使用的是 openjdk 的 docker ' slim images' ,则该图像不再包含包 'fontconfig' 和 'libfreetype6'。

Check the difference in docker file of openjdk:11-slim and the docker file of openjdk:8-slim.查看openjdk:11-slim的docker文件和openjdk:8-slim的docker 文件的区别。

You could either pick another docker image (eg openjdk:11-windowsservercore ), or install the packages yourself in your docker file:您可以选择另一个 docker 映像(例如openjdk:11-windowsservercore ),也可以自己在 docker 文件中安装软件包:

RUN apt-get update; apt-get install -y fontconfig libfreetype6 

The underlying issues is something else根本的问题是别的

I just created a simple class which does class loading of X11FontManager and when I ran it complained我刚刚创建了一个简单的类,它执行 X11FontManager 的类加载,当我运行它时抱怨

unable to link "libfreetype6"

once I installed it using一旦我安装它使用

apt-get install libfreetype6

started throwing could not link "libfontconfig1.so"开始抛出无法链接“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阅读本文并了解几件事https://medium.com/azulsystems/using-jlink-to-build-java-runtimes-for-non-modular-applications-9568c5e70ef4

2021-06-23 03:44:37.950  INFO 1 --- [       Thread-7] ReportService   : Template path : /jasper/MgmtSummary.jrxml
Exception in thread "Thread-7" java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:398)

I was getting the above error when I was using docker image gcr.io/distroless/java-debian10:11我在使用gcr.io/distroless/java-debian10:11 image gcr.io/distroless/java-debian10:11时遇到上述错误

And this was fixed when I change the image to adoptopenjdk/openjdk11当我将图像更改为采用adoptopenjdk/openjdk11时,此问题已修复

Problem occurs when you use openjdk docker image in alpine version for example :例如,在alpine版本中使用 openjdk docker 映像时会出现问题:

adoptopenjdk/openjdk11:jre-11.0.11_9-alpine . adoptopenjdk/openjdk11:jre-11.0.11_9-alpine

You need chenge image to full version : adoptopenjdk/openjdk11:jre-11.0.11_9您需要完整版的成格镜像:采用adoptopenjdk/openjdk11:jre-11.0.11_9

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

相关问题 无法初始化类 sun.awt.X11FontManager alpine java 17 - Could not initialize class sun.awt.X11FontManager alpine java 17 无法在高山Linux上使用openjdk 8初始化类sun.awt.X11FontManager - Could not initialize class sun.awt.X11FontManager using openjdk 8 on alpine linux NoClassDefFoundError:无法初始化类sun.awt.X11GraphicsEnvironment - NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment sun.awt.X11FontManager: java.lang.reflect.InvocationTargetException (Arch Linux) - sun.awt.X11FontManager: java.lang.reflect.InvocationTargetException (Arch Linux) 无法运行IntelliJ-NoClassDefFoundError:无法初始化类sun.awt.X11GraphicsEnvironment - Cannot run IntelliJ - NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment 无法在 Solaris 上初始化类 sun.awt.X11GraphicsEnvironment - Could not initialize class sun.awt.X11GraphicsEnvironment on Solaris MuleESB-无法初始化类sun.awt.SunToolkit - MuleESB - Could not initialize class sun.awt.SunToolkit 对于sun.awt.X11GraphicsEnvironment,Gradle构建失败,NoClassDefFoundError:mergeDebugResources - Gradle build fails with NoClassDefFoundError for sun.awt.X11GraphicsEnvironment in :mergeDebugResources NoClassDefFoundError-无法初始化类……? - NoClassDefFoundError - could not initialize class …? NoClassDefFoundError无法初始化类 - NoClassDefFoundError could not initialize class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM