简体   繁体   English

如何从命令行启动.jar文件GUI?

[英]How do I launch a .jar file GUI from the command line?

I'm trying to write a quick script to launch a couple of (3rd party) .jar files. 我正在尝试编写一个快速脚本来启动几个(第三方).jar文件。 Normally I would navigate to the folder and double click the files individually which brings up a GUI. 通常,我将导航到该文件夹​​并分别双击文件,这将弹出一个GUI。

When I run java -jar [filename].jar it doesn't open the GUI and instead runs as a command line app. 当我运行java -jar [filename].jar它不会打开GUI,而是作为命令行应用程序运行。 Which makes sense I guess. 我猜这很有道理。

Is there any way to force it to open the GUI when running on the command line? 在命令行上运行时,是否有任何方法可以强制其打开GUI?

I'm using a Mac. 我正在使用Mac。

Thanks! 谢谢!

Double clicking on a .jar file on a Mac runs the .jar via an app hidden in a system folder called Jar Launcher. 在Mac上双击.jar文件可通过隐藏在名为Jar Launcher的系统文件夹中的应用程序运行.jar。

To simulate the double click from the command line you can run the Jar Launcher and pass it the .jar file as a parameter. 要模拟命令行中的双击,您可以运行Jar Launcher并将.jar文件作为参数传递给它。

open /System/Library/CoreServices/Jar\\ Launcher.app ~/Path/to/JarFile.jar

No idea why or how the .jar was showing different behaviour from double clicking when running with java -jar but this fixes it (on a Mac at least). 不知道为什么或使用java -jar运行时,.jar表现出与双击不同的行为,但这可以解决(至少在Mac上)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM