Java 无法在 Solaris 上初始化类 sun.awt.X11GraphicsEnvironment

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21131855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:48:44  来源:igfitidea点击:

Could not initialize class sun.awt.X11GraphicsEnvironment on Solaris

javasolarisjvm-arguments

提问by Deka

I am running into this error while running my installer on a Solaris machine:

我在 Solaris 机器上运行我的安装程序时遇到了这个错误:

Installing...
-------------

 [==================|==================|==================|==================]
 [---Invocation of this Java Application has caused an InvocationTargetException. This application will now exit. (LAX)

Stack Trace:
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:186)
        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
        at sun.awt.X11FontManager.isHeadless(X11FontManager.java:487)
        at sun.awt.X11FontManager.getFontPath(X11FontManager.java:767)
        at sun.font.SunFontManager.getPlatformFontPath(SunFontManager.java:3288)
        at sun.font.SunFontManager.run(SunFontManager.java:3314)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.SunFontManager.loadFonts(SunFontManager.java:3310)
        at sun.awt.X11FontManager.loadFonts(X11FontManager.java:439)
        at sun.font.SunFontManager.findFont2D(SunFontManager.java:2347)
        at sun.font.SunFontManager.findFont2D(SunFontManager.java:2285)
        at java.awt.Font.getFont2D(Font.java:498)
        at java.awt.Font.getFamily(Font.java:1187)
        at java.awt.Font.getFamily_NoClientCode(Font.java:1161)
        at java.awt.Font.getFamily(Font.java:1153)
        at ZeroGrs.a(DashoA10*..)
        at ZeroGrs.a(DashoA10*..)
        at ZeroGrs.a(DashoA10*..)
        at ZeroGrs.a(DashoA10*..)
        at ZeroGrs.a(DashoA10*..)
        at ZeroGrs.a(DashoA10*..)
        at com.zerog.ia.installer.actions.InstallUninstaller.a(DashoA10*..)
        at com.zerog.ia.installer.actions.InstallUninstaller.d(DashoA10*..)
        at com.zerog.ia.installer.actions.InstallUninstaller.installSelf(DashoA10*..)
        at com.zerog.ia.installer.InstallablePiece.install(DashoA10*..)
        at com.zerog.ia.installer.actions.InstallDirectory.install(DashoA10*..)
        at com.zerog.ia.installer.actions.InstallDirectory.install(DashoA10*..)
        at com.zerog.ia.installer.InstallablePiece.install(DashoA10*..)
        at com.zerog.ia.installer.GhostDirectory.install(DashoA10*..)
        at com.zerog.ia.installer.InstallablePiece.install(DashoA10*..)
        at com.zerog.ia.installer.Installer.install(DashoA10*..)
        at com.zerog.ia.installer.LifeCycleManager.b(DashoA10*..)
        at com.zerog.ia.installer.LifeCycleManager.a(DashoA10*..)
        at com.zerog.ia.installer.Main.main(DashoA10*..)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at com.zerog.lax.LAX.launch(DashoA10*..)
        at com.zerog.lax.LAX.main(DashoA10*..)

I tried configuring JAVA_OPTSwith -Djava.awt.headless=truebut it doesn't work!

我尝试配置JAVA_OPTS-Djava.awt.headless=true但它不起作用!

Any has other solution to the issue?

有没有其他解决方案?

回答by Edgard Leal

Try running this code in a constructor of a servlet

尝试在 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 POIwhen you want to create a sheet with auto size columns.

这是当您想要创建具有自动调整大小列的工作表时,在Apache POI 中记录和解释的此问题的示例。

回答by 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.

解决了这个问题。这是我的个人资料,我已将 DISPLAY 设置为一台主机,但该主机已不存在。我已经正确设置了它并且它起作用了。

$ export DISPLAY=

$ export DISPLAY=

Or

或者

$ unset DISPLAY

$ unset DISPLAY

回答by Christian Bongiorno

Actually,

实际上,

-Djava.awt.headless=true

Does not fixthe 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.

解决问题,它回避它。问题是您尝试运行的应用程序想要在 XWindows 中使用 UI 运行。此错误表示 Java 中的“dll not found”或“.so not found”等价物。实际执行此操作所需的库不存在于您使用的 JVM 类路径中。

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

问题是您使用的是 OpenJDK(或其他一些 Java 版本,如 Jikes),而 awt 是 Java 中因许可原因无法开源的部分之一。所以,这个类不是故意存在的,也永远不会在 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 fixthis 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.

你让它在命令行模式下运行,并不是所有的应用程序都能做到这一点。在你的情况下,你逃脱了。实际解决此问题的唯一方法是在类路径中获取该类及其所有依赖类。最简单的方法是切换到 sun JRE。

回答by u7565209

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.

我的 Linux 服务器也有同样的问题。我不知道发生了什么神奇的事情,通过在我的 Linux 机器上安装 Xorg 完美地解决了问题。

sudo apt-get install xorg openbox

回答by raviteja katari

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.

确保您没有更改任何主机名,然后发生此问题,如果是这种情况,则问题出在主机名上。

回答by user2737538

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.shor ${TOMCAT_HOME}/bin/catalina.batfile:

编辑${TOMCAT_HOME}/bin/catalina.sh${TOMCAT_HOME}/bin/catalina.bat文件:

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.io.tmpdir="$CATALINA_TMPDIR"并在此行下添加:

-Djava.awt.headless=true \

There are a total of seven places, which can be solved after the restart.

一共七个地方,重启后即可解决。