i'm developing a simple application using java swing that i would like to used in Windows, MacOS and Linux. Of course i'm trying to integrate it with the OS the best i can.
For MacOS i have this code that allows me to set the app name in the global menu and the action for the "About" button.
I'm using the following code:
if(System.getProperty("os.name").toUpperCase().startsWith("MAC")){
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "My app name");
System.setProperty("apple.awt.application.name", "My app name");
//Need for macos global menubar
System.setProperty("apple.laf.useScreenMenuBar", "true");
try{
com.apple.eawt.Application app = com.apple.eawt.Application.getApplication();
app.setDockIconImage(Toolkit.getDefaultToolkit().getImage(MainGUI.class.getResource("images/icon.png")));
app.setAboutHandler(new com.apple.eawt.AboutHandler() {
@Override
public void handleAbout(com.apple.eawt.AppEvent.AboutEvent aboutEvent) {
AboutDialog a = new AboutDialog();
a.setTitle("About");
a.pack();
a.setResizable(false);
centerDialogInScreen(a);
a.setVisible(true);
}
});
} catch (Throwable e){
//This means that the application is not being run on MAC OS.
//Just do nothing and go on...
}
}
When i run my application on a non-macos JAVA since its JRE doesn't have the com.apple.eawt.* classes the JVM should throw an NoDefClassFoundError that i'm catching and go on, right?
It doesn't seem to be doing that, when i launch my application ".jar" i get the following (on Windows):
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/apple/eawt/AboutHandler
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.apple.eawt.AboutHandler
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
What am i missing here?