运行 Jar 并从服务器显示

运行 Jar 并从服务器显示

我有一个 Jar 文件,我想在我的服务器上运行它。当我使用运行时,java -jar MyJar.jar出现此错误:

No protocol specified
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
    at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at sun.awt.X11GraphicsEnvironment.access$200(Unknown Source)
    at sun.awt.X11GraphicsEnvironment$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.awt.X11GraphicsEnvironment.<clinit>(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at java.awt.GraphicsEnvironment.createGE(Unknown Source)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(Unknown Source)
    at java.awt.Window.initGC(Unknown Source)
    at java.awt.Window.init(Unknown Source)
    at java.awt.Window.<init>(Unknown Source)
    at java.awt.Frame.<init>(Unknown Source)
    at javax.swing.JFrame.<init>(Unknown Source)
    at Dots.main(Dots.java:13)

经过一番研究,我找到了各种解决方案,但没有一个能解决我的问题:export DISPLAY=:0不幸xhost +的是,这又回来了

No protocol specified
xhost:  unable to open display ":0"   

编辑* 也尝试过java -Djava.awt.headless=true -jar MyJar.jar但出现此错误:

Exception in thread "main" java.awt.HeadlessException
    at java.awt.GraphicsEnvironment.checkHeadless(Unknown Source)
    at java.awt.Window.<init>(Unknown Source)
    at java.awt.Frame.<init>(Unknown Source)
    at javax.swing.JFrame.<init>(Unknown Source)
    at Dots.main(Dots.java:13)

有什么解决办法吗?

答案1

您还没有列出您排除的内容,那么:

java -Djava.awt.headless=true -jar MyJar.jar 

答案2

您可能需要在该显示器上启动 X 客户端(如 VNC)。您已经这样做了吗?

答案3

答案很简单ssh -Y <server>,或者ssh -X <server>这将启用 X11Forwarding,从而允许您运行程序。但是对我来说,-X 选项会在登录到服务器一段时间后使 X11Forwarding 超时。-Y 将保持 x11Fowarding 不变。

相关内容