开发者

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 li开发者_如何学运维ne:

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?


You can do this by setting the system property in your code in the main method or some other method which is called at the very beginning of the application:

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


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


Inside my main method, I would make use of the built in os.name parameter and default your command line argument as appropriate if it was not otherwise set.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜