通过Linux终端运行Java GUI应用程序

时间:2011-03-09 05:43:42

标签: java linux user-interface bash ubuntu

我在Ubuntu尝试通过终端运行Java GUI应用程序。当我尝试运行它时,我收到了HeadlessException。下面是堆栈跟踪:

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)

我在运行应用程序之前尝试了export DISPLAY=:0.0,但这没有任何效果。你如何通过Bash运行GUI应用程序?

4 个答案:

答案 0 :(得分:27)

我猜你只安装了default-jre-headless包。检查您是否有default-jre

答案 1 :(得分:5)

我有这个例外。我尝试将无头设置设置为false,这对我有用:

export JAVA_TOOL_OPTIONS='-Djava.awt.headless=false'

答案 2 :(得分:3)

如果您通过以下命令在Ubuntu上运行应用程序:

java -jar MyJar.jar

然后使用OpenJDK。尝试安装Sun JDK并运行您的应用程序,如:

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

答案 3 :(得分:0)

如果您没有GUI,则无法运行它。您是否正在远程运行(例如,SSH)?

如果是这样,请查看您用于远程访问的系统。例如,使用SSH,您需要查看AllowX11Forwarding设置(SSH FAQ entry)