Home > database >  Run Swing GUI through SSH terminal with Ubuntu client and server
Run Swing GUI through SSH terminal with Ubuntu client and server

Time:09-16

I am testing out a program on a headless PC with Ubuntu 20.04 loaded. On my development PC (client) I package the program into a jar and copy the jar to the headless PC (server) using ssh. The jar includes a basic Swing GUI that I'd like to interact with using the development PC. The development PC also runs Ubuntu 20.04.

I have tried setting the X11 DISPLAY variable on the server

export DISPLAY=:0.0

But it doesn't work, what can I do to fix this?

EDIT Before setting the DISPLAY variable the error message is:

Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
    at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208)
    at java.desktop/java.awt.Window.<init>(Window.java:548)
    at java.desktop/java.awt.Frame.<init>(Frame.java:423)
    at java.desktop/java.awt.Frame.<init>(Frame.java:388)
    at java.desktop/javax.swing.JFrame.<init>(JFrame.java:180)
    at com.mochilafulfillment.agv.gui.RemoteGui.<init>(RemoteGui.java:21)
    at com.mochilafulfillment.agv.modes.RemoteControlMode$1.run(RemoteControlMode.java:30)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

And after setting the DISPLAY variable the error message is:

java.awt.AWTError: Cant connect to X11 window server using '0.0' as the value of the DISPLAY variable.
    at java.desktop/sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at java.desktop/sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:102)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.desktop/sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:61)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:315)
    at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:101)
    at java.desktop/java.awt.GraphicsEnvironment$LocalGE.<clinit>(GraphicsEnvironment.java:83)
    at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:129)
    at java.desktop/sun.awt.X11.XToolkit.<clinit>(XToolkit.java:232)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:315)
    at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:588)
    at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:583)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.desktop/java.awt.Toolkit.getDefaultToolkit(Toolkit.java:582)
    at java.desktop/java.awt.Toolkit.getEventQueue(Toolkit.java:1498)
    at java.desktop/java.awt.EventQueue.invokeLater(EventQueue.java:1312)
    at java.desktop/javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1421)
    at com.mochilafulfillment.agv.modes.RemoteControlMode.run(RemoteControlMode.java:27)
    at com.mochilafulfillment.agv.Agv.run(Agv.java:53)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

CodePudding user response:

It is not possible to run a Swing GUI through an SSH terminal.

I will make a separate GUI application that runs on the client and sends data (likely via HTTP) to the server which runs the main application.

  • Related