java - 尝试使Java Swing应用程序可以远程显示(Linux)

标签 java swing ssh x11

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

通过在此处搜索,我知道这取决于X11,并且需要在客户端和服务器端都启用X11。

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

在客户端,我正在同时使用-X(大写)和-v选项调用ssh。 -v选项导致显示一堆调试行,但是没有任何调试行引用X11。我一直在寻找引用X11转发的内容,但是什么也没显示(也没有任何迹象表明它被抑制了)。另外,我在/ etc / ssh_config中检查了客户端(MacOS),并将“ForwardX11”和“ForwardX11Trusted”都设置为"is"。

无论如何尝试运行该程序,都会收到“headless”异常,并且堆栈跟踪的确包含了我的应用程序(因此,我知道我正在调用正确的程序而没有类路径问题)。

这是调用不带-X选项的ssh时得到的错误(和相同的堆栈跟踪)。

然后,我尝试了“export DISPLAY =:0.0”和“1.0”,并得到了另一个异常(“无法使用':0.0'作为显示变量的值连接到X11窗口服务器”)。

我不太了解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 dsmith@app1
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 hmac-sha1-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-sha1-etm@openssh.com 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
dsmith@app1's password:
debug1: Authentication succeeded (password).
Authenticated to app1 ([16x.24y.5z.7w]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: client_input_global_request: rtype hostkeys-00@openssh.com 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)

最佳答案

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

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

关于java - 尝试使Java Swing应用程序可以远程显示(Linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45516827/

相关文章:

git - Git对象权限-SSH

c# - 如何在 C# 中的 SSH 服务器上运行命令?

java - 这是在 Java 中释放 SQLite 连接的最佳方法吗?

java - 如何将扩展的 jpanel 添加到 jframe

java - 如何在android中实现滑动 View

java - 轻量级组件中剪辑区域的处理与文档不匹配?

java - 如何在java中重复代码

linux - 无法连接到远程机器 'ssh_exchange_identification: read: Connection reset by peer'

java - Cxf + Spring-boot (org.apache.cxf.bus.extension.ExtensionException)

java - 如何为要并行处理的 java 列表中的每个项目添加索引