15

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?

4 Answers 4

30

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

Sign up to request clarification or add additional context in comments.

3 Comments

Worked for me, thanks. Package was there with Ubuntu but not installed. "sudo apt-get install openjdk-6-jre"
worked for me too. in my case i had only default-jdk-headless installed. so, I installed default-jdk
just a remark: in Fedora/RedHat distributions this package is called 'java-N.N.N-openjdk' (where NNN is the version number)
8

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'

1 Comment

This didn't work for me but did cause it to provide a more helpful message (missing library)
3

If you run your application on Ubuntu by the command:

java -jar MyJar.jar

then OpenJDK is used. Try to install the Sun JDK and run your application like:

/usr/java/jre1.6.0_22/bin/java -jar MyJar.jar

1 Comment

Alternatively, you can use the command update-java-alternatives to select the default Java on your machine.
0

If you don't have a GUI, you can't run it. Are you running remotely (for example, SSH)?

If so, look into the system that you're using for remote access. For example, with SSH you want to look at the AllowX11Forwarding setting (SSH FAQ entry).

3 Comments

I am not remote. I'm running Ubuntu on my laptop.
Then if you don't have a GUI running, you can't run a GUI app.
Ah, you're running this through a terminal in X? In that case, you need to look at the terminal's instructions to ensure that the DISPLAY variable is being set properly. Unfortunately, there are as many possibilities as there are different terminals. Try using a basic terminal such as XTerm for troubleshooting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.