Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Java GUI applications through a Linux terminal

I'm on Ubuntu trying to run a Java GUI application through the terminal. I'm getting a HeadlessException when I try to run it. Below is the stack trace:

Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException
    at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:173)
    at java.awt.Window.<init>(Window.java:437)
    at java.awt.Frame.<init>(Frame.java:419)
    at java.awt.Frame.<init>(Frame.java:384)
    at javax.swing.JFrame.<init>(JFrame.java:174)
    at gui.ImageViewer.<init>(ImageViewer.java:34)
    at displayrunner.DisplayRunner$1.run(DisplayRunner.java:15)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:647)
    at java.awt.EventQueue.access$000(EventQueue.java:96)
    at java.awt.EventQueue$1.run(EventQueue.java:608)
    at java.awt.EventQueue$1.run(EventQueue.java:606)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:617)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)

I tried export DISPLAY=:0.0 before running the application, but that had no effect. How do you run a GUI application through Bash?

like image 252
Tyler Treat Avatar asked Mar 09 '11 05:03

Tyler Treat


2 Answers

I guess you only have the default-jre-headless package installed. Check that you have default-jre.

like image 60
Denis Tulskiy Avatar answered Oct 21 '22 17:10

Denis Tulskiy


I had this exception. I tried setting the headless setting to false, and it worked for me:

export JAVA_TOOL_OPTIONS='-Djava.awt.headless=false'
like image 43
AkD Avatar answered Oct 21 '22 16:10

AkD