I wrote a java file including javaFX. Now, I want to run this file, like java -jar example.jar But I'd like to suppress the graphical output. 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. JAR files have manifests. In order to run your JAR using the command java -jar example.jar
, the manifest must have a Main-Class
entry. And your main class must have a main()
method.
So launch your app like so...
java -jar example.jar NO_GUI
And in your main()
method, write something like the following...
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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.