Could not initialize class sun.awt.X11FontManager(POI)
Overview
2024-04-22 18:41:20 [ERROR] [http-nio-8082-exec-5] o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/common/api] threw exception [Handler dispatch failed: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager] with root cause
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:466)
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:82)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.desktop/java.awt.Font.getFont2D(Font.java:526)
at java.desktop/java.awt.Font.canDisplayUpTo(Font.java:2279)
at java.desktop/java.awt.font.TextLayout.singleFont(TextLayout.java:469)
at java.desktop/java.awt.font.TextLayout.<init>(TextLayout.java:530)
at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273)
at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:248)
at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:233)
at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:555)
at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:537)
at org.okestro.tps.common_lib.util.excelTest.ExcelUtil.createExcel(ExcelUtil.java:133)
at org.okestro.tps.common_lib.util.excelTest.ExcelUtil.downloadExcel(ExcelUtil.java:83)
The error message you provided indicates a `java.lang.NoClassDefFoundError` with the root cause being the initialization failure of `sun.awt.X11FontManager`. This error is commonly encountered when running Java applications that require access to fonts or font management, such as Apache POI when working with Excel files.
The issue seems to be related to font management and rendering within the Apache POI library. The `sun.awt.X11FontManager` class is part of the Java AWT (Abstract Window Toolkit) library and is responsible for font management in Java applications.
Here are some steps you can take to address this issue:
Trouble Shooting
POI라이브러리를 이용해 엑셀구성시 스타일관련된 작업을 진행하던 도중 오류가 발생
해당 애플리케이션을 빌드하기위해 명시된 빌드이미지는 jdk17-slim이였고, 해당 빌드이미지는 경량화 목적성을 가지기에 아래와 같은 Font Manager 관련된 패키지가 존재하지않음
- fontconfig
- libfreetype6
빌드이미지 도구를 변경하여 이슈 fix