You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
A shellscript JavaApplicationStub for Java Apps on Mac OS X that works with both Apple's and Oracle's plist format.
5
+
6
+
7
+
Why
8
+
---
9
+
10
+
Whilst developing some Java apps for Mac OS X I was facing the problem of supporting two different Java versions – the "older" Apple versions and the "newer" Oracle versions.
11
+
12
+
**Is there some difference, you might ask?** Yes, there is!
13
+
14
+
1. The spot in the file system where the JRE or JDK is stored is different:
15
+
* Apple Java 1.5/1.6: `/System/Library/Java/JavaVirtualMachines/`
2. Mac Apps built with tools designed for Apple's Java (like Apple's JarBundler or the [ANT task "Jarbundler"](http://informagen.com/JarBundler/)) won't work on Macs with Oracle Java 7 and no Apple Java installed.
19
+
* This is because the Apple `JavaApplicationStub` only works for Apple's Java and their `Info.plist` style to store Java properties.
20
+
* To support Oracle Java 7 you would need to built a separate App package with Oracles [ANT task "Appbundler"](https://java.net/projects/appbundler).
21
+
* Thus you would need the user to know which Java distribution he has installed on his Mac. Not very user friendly...
22
+
23
+
3. Oracle uses a different syntax to store Java properties in the applications `Info.plist` file. A Java app packaged as a Mac app with Oracles Appbundler also needs a different `JavaApplicationStub` and therefore won't work on systems with Apple's Java...
24
+
25
+
*So why, oh why, couldn't Oracle just use the old style of storing Java properties in `Info.plist` and offer a universal JavaApplicationStub?!*:rage:
26
+
27
+
Well, since I can't write such a script in C, C# or whatever fancy language, I wrote it as a shell script. And it works! ;-)
28
+
29
+
How it works
30
+
------------
31
+
32
+
You don't need a native `JavaApplicationStub` file anymore...
33
+
34
+
The shell script reads JVM properties from `Info.plist` regardless of which format they have, Apple or Oracle, and feeds it to a commandline `java` call:
It sets the classpath, the dock icon, the *AboutMenuName* (in Xdock style) and then every *JVMOptions*, *JVMDefaultOptions* or *JVMArguments* found in the `Info.plist` file.
56
+
57
+
The name of the *main class* is also retrieved from `Info.plist`. If no *main class* could be found, an applescript error dialog is shown and the script exits with *exit code 1*.
58
+
59
+
Also, there is some *foo* happening to determine which Java version is installed. Here's the list in which order system properties are checked:
60
+
61
+
1. system variable `$JAVA_HOME`
62
+
2.`/usr/libexec/java_home` symlinks
63
+
3. symlink for old Apple Java: `/Library/Java/Home/bin/java`
64
+
4. hardcoded fallback to Oracle's JRE Plugin: `/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java`
65
+
66
+
If none of these could be found or executed, an applescript error dialog is shown saying that Java need to be installed.
67
+
68
+
What you need to do
69
+
-------------------
70
+
71
+
Use whichever ANT task you like:
72
+
* the great opensource ["Jarbundler"](http://informagen.com/JarBundler/)
73
+
* my JarBundler [fork on github](https://github.com/tofi86/Jarbundler) which supports *MixedLocalization*
osascript -e "tell application \"System Events\" to display dialog \"ERROR launching ${CFBundleName}!\n\nNo MainClassName specified!\nJava application cannot be started!\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1 with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)"
osascript -e "tell application \"System Events\" to display dialog \"ERROR launching ${CFBundleName}!\n\nYou need to have JAVA installed on your Mac!\nVisit http://java.com for more information...\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1 with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)"
0 commit comments