[英]Is there a way to run a -.jar file (created with javaFx) without displaying anything(GUI, progressbar, …)?
I wrote a java file including javaFX. 我写了一个包含javaFX的java文件。 Now, I want to run this file, like java -jar example.jar But I'd like to suppress the graphical output.
现在,我想运行这个文件,比如java -jar example.jar但是我想要抑制图形输出。 Is there any possible, like a flag or anything else, to do this?
有没有可能,像旗帜或其他任何东西,这样做? My program normally shows a progressbar and after that a video of the simulation.
我的程序通常会显示一个进度条,之后会显示一个模拟视频。
Thanks a lot. 非常感谢。
To elaborate on JB Nizet 's comment. 详细阐述JB Nizet的评论。 JAR files have manifests.
JAR文件有清单。 In order to run your JAR using the command
java -jar example.jar
, the manifest must have a Main-Class
entry. 要使用命令
java -jar example.jar
运行JAR,清单必须具有Main-Class
条目。 And your main class must have a main()
method. 你的主类必须有一个
main()
方法。
So launch your app like so... 所以启动你的应用程序就好了...
java -jar example.jar NO_GUI
And in your main()
method, write something like the following... 在你的
main()
方法中,写下类似的东西......
public static void main(String[] args) {
if (args.length > 0 && "NO_GUI".equals(args[0]) {
// Don't show GUI
}
else {
// Show the GUI.
}
}
你可以在场景上调用hide()
,这样窗口就会消失。
There is not really a way to force this. 没有办法强迫这一点。
Instead, implement it as feature. 相反,将其实现为功能。 Create a command line argument
nogui
and react to it: 创建命令行参数
nogui
并对其作出反应:
public static void main(String[] args) {
boolean useGui = true;
if (args.length > 0 && args[0].equals("nogui")) {
doNotUseGui = false;
}
// Create your program and give it the flag
Program prog = new Program(useGui);
...
}
Note that theoretically it would be possible to hack your application and remove any such calls, or to suppress the calls on a native level. 请注意,从理论上讲,可以破解您的应用程序并删除任何此类调用,或抑制本机级别的调用。 But I guess that is not really the route you want to go.
但我想这不是你想去的路线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.