Could not initialize class sun. awt. X11graphicsenvironment solution

Time:2022-5-13

Could not initialize class sun. awt. X11graphicsenvironment solution

Error message:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment

Error reporting reason:

The API of a java server to process images basically needs to run an X-server to use AWT (Abstract window toolkit). Therefore, the problem must be that the X-server function cannot be realized when the server is started. The reason for the error is that Linux failed to start the xserver service

Solution:

1. Server installation xserver

This service is generally included in the graphical interface group and is not tested in person;

2. Run headless server plus – DJava awt. headless=true

Jdk1 is required Version above 4; Add the option – DJava. In the Java – jar startup command of the problematic server service awt. headless=true; (pro test, valid)

Example:

#Tomcat adds this parameter to Catalina Java for Java_ In opts parameters
JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -Djava.awt.headless=true"
#The springboot project adds parameters to the startup command
/usr/java/jdk1.8.0_191/bin/java -jar  -Djava.awt.headless=true -Xms128m -Xmx512m  spring-demo-1.0-SNAPSHOT.jar

This work adoptsCC agreementThe author, link and reprint of this article must be indicated

:kissing_ closed_ eyes: