简体   繁体   中英

How to run java application with built-in command line arguments?

I am making a Java application that is stored in a .jar file and can be launched by opening the jar file either from the command line or from clicking the icon.

For the Mac version of the app, I would like the menu bars to appear at the top of screen in the Mac style instead of in the window (the Windows style). I know this can be done with the command line:

java -jar App.jar -Dcom.apple.macos.useScreenMenuBar=true

But this won't work if the user doesn't know how to do this. Is there a way to make this command line argument "built in" to the jar file?

您可以通过在代码的main方法或应用程序开始时调用的其他方法中设置系统属性来实现此目的:

System.setProperty("com.apple.macos.useScreenMenuBar", "true")

I would suggest that you bundle the .jar into a standard mac .app file. Then, in Info.plist, you can specify all sorts of runtime items, including "Arguments" and "Properties". Take a look at http://developer.apple.com/library/mac/#documentation/Java/Reference/Java_InfoplistRef/Articles/JavaDictionaryInfo.plistKeys.html

Is is necessary to do it with the command line? You could check it in code with System.getProperty("os.name").

在我的主要方法中,我将使用内置的os.name参数,如果没有另外设置,则默认使用命令行参数。

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.

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