java 假X11显示器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/494442/
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-10-29 12:38:56  来源:igfitidea点击:

Fake X11 display?

javalinuxawtx11

提问by ashchristopher

I have a Java program using AWT which I would like to run on a headless system. The display for the program does nothing other than display stats. When the program finishes, it exits. There is no user interaction on the display. The program creates an output file which I use in my build system.

我有一个使用 AWT 的 Java 程序,我想在无头系统上运行它。程序的显示除了显示统计信息之外什么都不做。当程序完成时,它退出。显示屏上没有用户交互。该程序创建了一个我在构建系统中使用的输出文件。

Is there a way to get the Java program to run without an X11 display configured? Can I force Java to run the program without trying to display anything? I do not have access to the source code (it is just .jar file), so I can't make modifications to the source.

有没有办法让 Java 程序在没有配置 X11 显示器的情况下运行?我可以强制 Java 运行程序而不尝试显示任何内容吗?我无权访问源代码(它只是 .jar 文件),因此我无法修改源代码。

Any thoughts on how I could get this to work?

关于如何让它发挥作用的任何想法?

回答by Charles Duffy

The underlying question here is how to run Java applications without an X server; providing a "fake" X server is only one option. In Java 1.4 and up, you can do the following:

这里的基本问题是如何在没有 X 服务器的情况下运行 Java 应用程序;提供“假”X 服务器只是一种选择。在 Java 1.4 及更高版本中,您可以执行以下操作:

java -Djava.awt.headless=true

This allows applications which use AWT to run on headless systems even without an X server.

这允许使用 AWT 的应用程序即使没有 X 服务器也可以在无头系统上运行。

回答by Peter B. Bock

Xvfb can do what you ask for. I've not used it myself, but here is a link to wikipedia: http://en.wikipedia.org/wiki/Xvfb

Xvfb 可以满足您的要求。我自己没有用过,但这里有一个维基百科的链接:http: //en.wikipedia.org/wiki/Xvfb

回答by vrdhn

You can use a vncserver.

您可以使用 vncserver。

vncserver :1001
export DISPLAY=localhost:1001
java..

The added advantages is that you can actually view the gui using vncserver 'just in case'

附加的优点是您实际上可以使用 vncserver '以防万一' 查看 gui

回答by Joshua

Could also run Xvnc in a low resolution and color depth.

也可以在低分辨率和颜色深度下运行 Xvnc。

回答by Thorbj?rn Ravn Andersen

As mentioned by Charles Duffy the traditional method is to tell Java to go headless.

正如 Charles Duffy 所提到的,传统的方法是告诉 Java 去无头。

Note that you can always mount the jar in Eclipse and use jad+jadclipse to see what it actually does, and perhaps even override a class if you need to by putting another class-file in "front" of it in the classpath.

请注意,您始终可以在 Eclipse 中挂载 jar 并使用 jad+jadclipse 来查看它的实际作用,如果需要,甚至可以通过将另一个类文件放在类路径中的“前面”来覆盖一个类。

A facility that might be relevant if the program uses Java2D is that newer Java versions use optimizations in the X11 server to render faster. This alone might be a reason to devote an X11 server attached to a high performance graphics card to your graphics processing.

如果程序使用 Java2D,一个可能相关的工具是较新的 Java 版本使用 X11 服务器中的优化来更快地呈现。仅此一项就可能是将连接到高性能显卡的 X11 服务器用于图形处理的原因。

回答by Matthew Molloy

I was able to get headless mode in OpenJFX with the command line arguments

我能够使用命令行参数在 OpenJFX 中获得无头模式

-Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw

回答by webclimber

I've used with great success in the past the PJAlibraries, they don't seem to be maintained anymore, but then again, just just want to run...

过去我成功地使用了PJA库,它们似乎不再维护了,但话说回来,只是想运行......