我在 CentOS 服务器中运行 Java 应用程序时遇到问题。当我触发以下命令时:
java -jar the-application.jar
我收到以下错误:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207)
at java.awt.Window.<init>(Window.java:535)
at java.awt.Frame.<init>(Frame.java:420)
at java.awt.Frame.<init>(Frame.java:385)
at javax.swing.JFrame.<init>(JFrame.java:174)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:745)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:706)
at java.awt.EventQueue$3.run(EventQueue.java:704)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:715)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:218)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:133)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:122)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:118)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:110)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
我尝试使用以下命令定义 DISPLAY 变量,但这次只有错误发生了变化,命令再次失败:
设置显示变量的命令:
export DISPLAY=:0.0
错误:
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
根据不同论坛的建议,我也分别尝试了以下的变异,但没有运气:
export DISPLAY=:0
export DISPLAY=:99
export DISPLAY=:99.0
export DISPLAY=:1
export DISPLAY=:1.0
export DISPLAY=127.0.0.1:0
export DISPLAY=127.0.0.1:0.0
export DISPLAY=127.0.0.1:99
export DISPLAY=127.0.0.1:99.0
export DISPLAY=127.0.0.1:1
export DISPLAY=127.0.0.1:1.0
我尝试了"xhost + localhost"命令,所以也许它可以提供帮助,但是,我收到以下错误:
-bash: xhost: command not found
谁能帮我解决这个问题?提前谢谢大家。
您应该按照如下所述在系统上安装 lightDm:
http://siripong-computer-tips.blogspot.co.uk/2015/02/how-to-add-cinnamon-lightdm-to-centos-7.html
如果你在VMware上运行CentOS,你也应该在你的VMware上安装相关的工具。