问题
When my application written in Java
with SWT
runs under OS X
, both from under Eclipse
and from jar
, its name in the launchpad reads "java", like shown in the picture.
In the beginning of my code I call Display.setAppName("MyApp")
, and the name of the application in the menu bar and menu items is correct, it reads MyApp
, About MyApp
, Configure MyApp
, etc. The menu items behave properly, I can receive and handle the appropriate events.
So the problem pertains exclusively to the app name, shown in the launchpad. Is there any way to set the correct name to be shown in the launchpad programmatically, from the code, without creation of the application bundle?
P. S. The code is actually running under JVM that is started from within my code using ProcessBuilder
:
new ProcessBuilder("java -cp mypath MyClass my args").start();
a kind of recursion, needed to compute some jvm options and classpaths programmatically before starting the application.
回答1:
You should create a macOS app bundle with your jar, where you can put the bundle display name in the Info.plist
file of the bundle.This is well documented by Oracle (http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html).
The structure of a Java app bundle is documented by Apple as well: https://developer.apple.com/library/content/documentation/Java/Conceptual/Java14Development/03-JavaDeployment/JavaDeployment.html
回答2:
@m. vokhm I hope you have tried the following link
http://www.eclipse.org/articles/Article-Branding/branding-your-application.html
Also Check "3. How a launch can be triggered" in the link below
http://www.vogella.com/tutorials/EclipseLauncherFramework/article.html
回答3:
You should do the following during app initialization, before GUI is built:
// take the menu bar off the jframe
System.setProperty("apple.laf.useScreenMenuBar", "true");
// set the name of the application menu item
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "AppName");
// set the look and feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
But above code works in Java 1.5, this code may not work in 1.6
For new java see documentation:
- Either use -Xdock:name command-line property:-Xdock:name=YourAppName
- Or set CFBundleName in information property list file (plist)
来源:https://stackoverflow.com/questions/42319471/how-to-change-the-java-application-name-shown-in-the-mac-os-x-launchpad