1

I have a Java application written with Swing that I'm trying to run on a remote Linux server and display on my local machine (running MacOS).

By searching here, I know that this depends on X11, and that I need to enable X11 on both the client and server sides.

On the server side, X11 is installed by examining the /etc/ssh/sshd_config file and confirming that "X11Forwarding" is set to "yes". I also confirmed that xauth is installed and is on the path (in /usr/bin/xauth).

On the client side, I'm invoking ssh with both the -X (capital) and -v options. The -v option causes a bunch of debug lines to be displayed, but none reference X11 in any way. I was looking for something that referenced X11 forwarding, but nothing was displayed (and nothing indicating that it was suppressed either). Also, I checked the client side (MacOS) in the /etc/ssh_config and it has both "ForwardX11" and "ForwardX11Trusted" set to "yes".

Attempting to run the program anyway, I get a "headless" exception and the stack trace does include my application (so I know that I'm invoking the correct program without classpath issues).

This is the exact same error (and same stacktrace) that I get if invoking ssh without the -X option.

I then tried "export DISPLAY=:0.0" and "1.0" and get a different exception ("Can't connect to X11 window server using ':0.0' as the value of the display variable").

I don't know enough to understand if the X-Window server is something that needs to be running on the server or my local Mac.

If it's on the Mac, I don't know (yet) how to do that, but I'll research that. I'm just looking for a pointer in the right direction.

Here is the stack trace:

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)

The ssh login:

===> ~ $ 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)
Dave Smith
  • 33
  • 1
  • 6

3 Answers3

1

In X11 terminology, programs connect to X11 servers as clients. So the Swing program on your Linux server would be the client to the X-Server running on your Mac.

Now MacOS doesn't run an X11 server out of the box. You have to install and start one. I think https://www.xquartz.org/ is the right address, but I haven't used a Mac for a while.

sba
  • 1,829
  • 19
  • 27
0

To run applications on the remote machine and display it on your local machine, login to remote machine using following ssh command .

ssh -X username@hostIp
pvrforpranavvr
  • 2,708
  • 2
  • 24
  • 34
0

From this article:

"No X11 DISPLAY variable" - what does it mean?

If you're on the main display, then

    export DISPLAY=:0.0

or if you're using csh or tcsh

    setenv DISPLAY :0.0

before running your app.

In Java Swing and Java AWT, A headless exception means that there is no graphical user interface available on which to display the graphical window you are trying to display. In windows you can reproduce this by calling a Java swing program from a scheduled task that runs as a specific user (who is not logged in) and runs without access to the desktop. For this reason I focused on the following error message from your trace (great ticket btw, well documented attempts):

    No X11 DISPLAY variable was set

I tried a Google search for ’Java set X11 display variable’ and that’s how I found this article: "No X11 DISPLAY variable" - what does it mean?

Jonathan
  • 949
  • 1
  • 11
  • 13