Could not initialize class sun.awt.X11GraphicsEnvironment on Solaris

我与影子孤独终老i 提交于 2019-11-29 01:23:47

Try running this code in a constructor of a servlet

System.setProperty("java.awt.headless", "true"); 

or

Use this parameter in the startup script of the server:

-Djava.awt.headless=true

Here is an example of this problem documented and explaned in Apache POI when you want to create a sheet with auto size columns.

Actually,

-Djava.awt.headless=true

Does not fix the issue, it sidesteps it. The problem is the application you are trying to run want to run with a UI in XWindows. This error is saying the Java equivalent of 'dll not found' or '.so not found'. The library required to actually do this isn't present in the JVM classpath you are using.

The problem is you're using OpenJDK (or some other version of Java like Jikes) and the awt was one of the parts of Java that could not be open sourced for licensing reasons. So, this class doesn't exist on purpose and never will in OpenJDK

By declaring

-Djava.awt.headless=true

You are making it run in commandline mode and not all apps can do this. In your case, you got away with with. The only way to actually fix this issue is to get that class and all it's dependent classes in your classpath. The simplest way to do that is to switch to the sun JRE.

Deka

Solved the issue. It was my profile, where I have set my DISPLAY to one host, which is not alive. I have set it correctly and it worked.

$ export DISPLAY=

Or

$ unset DISPLAY

make sure you have not changed any hostname and after that this issue occured if this is the case then the problem is with hostname.

I had the same problem with my Linux server. I don't know what magic happened, the problem was fixed perfectly by installing Xorg on my Linux box.

sudo apt-get install xorg openbox
Usually, the program starts to activate the headless mode, telling the program, now you have to work in Headless mode, don't expect the hardware to help, you have to be self-reliant, relying on the computing power of the system to simulate these features: 
System.setProperty("java.awt.headless","true");

Edit the ${TOMCAT_HOME}/bin/catalina.sh or ${TOMCAT_HOME}/bin/catalina.bat file:

In all similar code below: 
"$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \ 
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \ 
-Djava.security.manager \ 
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \ 
-Dcatalina.base="$CATALINA_BASE" \ 
-Dcatalina.home="$CATALINA_HOME" \ 
-Djava.io.tmpdir="$CATALINA_TMPDIR" \

Add a sentence at the end: 
-Djava.awt.headless=true \

The revised content is as follows: 
Exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \ 
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \ 
-Dcatalina.base="$CATALINA_BASE" \ 
-Dcatalina.home="$CATALINA_HOME" \ 
-Djava.io.tmpdir="$CATALINA_TMPDIR" \ 
-Djava.awt.headless=true \

Directly search for the line -Djava.io.tmpdir="$CATALINA_TMPDIR" and add it under this line: 

-Djava.awt.headless=true \

There are a total of seven places, which can be solved after the restart. 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!