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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5241850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:10:55  来源:igfitidea点击:

Running Java GUI applications through a Linux terminal

javalinuxuser-interfacebashubuntu

提问by Tyler Treat

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:

我在 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.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
java -jar MyJar.jar
0(EventQueue.java:96) at java.awt.EventQueue.run(EventQueue.java:608) at java.awt.EventQueue.run(EventQueue.java:606) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext.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.0before running the application, but that had no effect. How do you run a GUI application through Bash?

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

采纳答案by Denis Tulskiy

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

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

回答by Kevin Lacquement

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

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

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

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

回答by ilalex

If you run your application on Ubuntu by the command:

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

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

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

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

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

回答by AkD

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

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

##代码##