Open Java .app application bundles with double click on a Mac without Apple’s Java 6

finderjava

In short: On a mac with a clean installation of Yosemite, doubleclicking a compiled Java mac-style .app application bundle fails to launch the app, unless Apple's Java 6 is installed, even if the current version of Java for the Mac from Oracle is installed.

At length: When Apple developed the Java SDK for macosx, you could open a .app mac-style application bundle written in Java by doubleclicking its icon in Finder, its app icon will show up in your dock while it was running, and its menu items would live in the Mac OS menu bar. Java apps behaved almost like native Mac apps.

On the other hand, if you install the current Java SDK from Oracle, you can execute your Java application with java -jar YourApp.app/Contents/Resources/Java/yourapp.jar, but you get a generic dock icon, your menu items live on top of the window instead of menu bar.

And if you don't have Java 6 from Apple installed on the machine, which is not included in recent versions of the OS but still available for download from Apple at this location (but it's pretty out of date at this point), then you just get an error message dialogue: "To open YourApp.app you need to install the legacy Java SE 6 runtime." with a link to Apple's outdated implementation, even though you already have Oracle's Java 8 installed already.

On a Mac with Java 8 from Oracle installed, but not Java 6 from Apple, is there a way to open a Java app from finder, or retain these other native platform compatibilities? Is there a way to force a .app bundle to use your preferred Java installation?

I'm basically asking the same question as To open “Eclipse” you need to install the legacy Java SE 6 runtime. Is there a solution to this problem other than installing legacy Java 6?

Also this question may be relevant: Application is using Java 6 from Apple instead of Java 7 from Oracle on Mac OS X?

At the questions Run java bundled in .app from command-line and Why is Java SE 6 Legacy required to open Intellij?, it is suggested that you can force your Java .app bundle to use a newer version of Java if you change the JVMVersion in YourApp.app/Contents/Info.plist, but this did not work for me. Those answers are from Java 1.7 era, maybe it's outdated?

Best Answer

From replies to a question I asked on Apple's java-dev list it would appear that on a Mac with Java 8 from Oracle installed, but not Java 6 from Apple, there is no current way to open a Java application bundle that was created using Apple's own old jar bundler technology. I suspect this is because the JavaApplicationStub is written to expect some aspect of Apple's Java not present in Oracle's Java.

From a user's point of view the only thing to do would seem to be to download and install Java 6 from https://support.apple.com/kb/DL1572 while it is still available.

From a developer's point of view the safest bet would be to embed Java within one's application bundle using a tool such as jwrapper (www.jwrapper.com). Alternatively there may be tools for creating a bundle that will run with Oracle's Java 8+.