试图让Java Swing应用程序远程显示(Linux)

问题描述:

我有一个用Swing编写的Java应用程序,我试图在远程Linux服务器上运行并显示在本地计算机上(运行MacOS)。试图让Java Swing应用程序远程显示(Linux)

通过搜索在这里,我知道,这依赖于X11,而且我需要在客户端和服务器端启用X11。

在服务器端,X11是通过检查的/ etc/ssh/sshd_config文件,并确认“打开X11Forwarding”设置为“是”安装。我还确认xauth已安装并位于路径中(位于/ usr/bin/xauth中)。

在客户端,我使用-X(大写)和-v选项来调用ssh。 -v选项会导致显示一堆调试行,但没有任何方式引用X11。我正在寻找引用X11转发的东西,但没有显示任何内容(并且没有任何内容表明它被抑制)。另外,我在/ etc/ssh_config中检查了客户端(MacOS),并将“ForwardX11”和“ForwardX11Trusted”都设置为“yes”。

试图想运行的程序,我得到一个“无头”异常和堆栈跟踪不包括我的应用程序(所以我知道我没有调用类路径问题正确的程序)。

这与我在不使用-X选项的情况下调用ssh时所得到的完全相同的错误(以及相同的堆栈跟踪)。

我然后试图“出口DISPLAY =:0.0”和“1.0”,并获得一个不同的异常(“无法使用连接到X11窗口服务器‘:0.0’作为显示变量的值”)。

我不知道有足够的了解,如果X-Window的服务器是什么,需要在服务器或我的本地的Mac上运行。

如果它在Mac上,我还不知道该怎么做,但我会研究它。我只是在正确的方向寻找一个指针。

这里是堆栈跟踪:

Exception in thread "main" java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it. 
    at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204) 
    at java.awt.Window.<init>(Window.java:536) 
    at java.awt.Frame.<init>(Frame.java:420) 
    at java.awt.Frame.<init>(Frame.java:385) 
    at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1758) 
    at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1833) 
    at javax.swing.JDialog.<init>(JDialog.java:272) 
    at com.fi.tools.gui.common.BaseGuiDriver.start(BaseGuiDriver.java:35) 
    at com.fi.tools.gui.CreateWorkflowTask.<init>(CreateWorkflowTask.java:38) 
    at com.fi.tools.gui.CreateWorkflowTask.<init>(CreateWorkflowTask.java:33) 
    at com.fi.tools.gui.CreateWorkflowTask.main(CreateWorkflowTask.java:28) 

的ssh登录:

===> ~ $ ssh -X -v [email protected] 
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011 
debug1: Reading configuration data /etc/ssh_config 
debug1: /etc/ssh_config line 20: Applying options for * 
debug1: Connecting to app1 [16x.24y.5z.7w] port 22. 
debug1: Connection established. 
debug1: identity file /Users/dave/.ssh/id_rsa type -1 
debug1: identity file /Users/dave/.ssh/id_rsa-cert type -1 
debug1: identity file /Users/dave/.ssh/id_dsa type -1 
debug1: identity file /Users/dave/.ssh/id_dsa-cert type -1 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_6.2 
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client aes128-ctr [email protected] none 
debug1: kex: client->server aes128-ctr [email protected] none 
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<2048<8192) sent 
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP 
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent 
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY 
debug1: Server host key: RSA ff:3c:2c:17:65:bc:be:c3:ba:c3:27:83:f6:6b:1d:e8 
debug1: Host 'app1' is known and matches the RSA host key. 
debug1: Found key in /Users/dave/.ssh/known_hosts:4 
debug1: ssh_rsa_verify: signature correct 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey,password 
debug1: Next authentication method: publickey 
debug1: Trying private key: /Users/dave/.ssh/id_rsa 
debug1: Trying private key: /Users/dave/.ssh/id_dsa 
debug1: Next authentication method: password 
[email protected]'s password: 
debug1: Authentication succeeded (password). 
Authenticated to app1 ([16x.24y.5z.7w]:22). 
debug1: channel 0: new [client-session] 
debug1: Requesting [email protected] 
debug1: Entering interactive session. 
debug1: client_input_global_request: rtype [email protected] want_reply 0 
debug1: Sending environment. 
debug1: Sending env LANG = en_US.UTF-8 
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64) 
+0

你能给我们完整的堆栈跟踪吗? –

+0

将这里添加为评论太长,所以我将它添加到上面的原始帖子中。 –

+0

好的,请运行'ssh -X -v your_server'(而不是'ssh -X your_server')并将输出添加到原始文章(它会提供有关X11转发方式的信息)。 –

在X11术语,程序连接到X11服务器作为客户端。因此,Linux服务器上的Swing程序将成为运行在Mac上的X-Server的客户端。

现在MacOS并不运行开箱即用的X11服务器。你必须安装并启动一个。我认为https://www.xquartz.org/是正确的地址,但我暂时还没有使用Mac。