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

2022-09-03 17:05:00

我在Ubuntu上试图通过终端运行Java GUI应用程序。当我尝试运行它时,我得到了一个无头异常。下面是堆栈跟踪:

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)

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


答案 1

我猜你只安装了软件包。检查您是否有 .default-jre-headlessdefault-jre


答案 2

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

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