Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit a8b1a6d

Browse files
committed
Added support for "JavaX" Plist key // fixes #9
1 parent f2555a1 commit a8b1a6d

File tree

3 files changed

+66
-21
lines changed

3 files changed

+66
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
ChangeLog
22
---------
33

4+
### v0.9.0 (2015-05-15)
5+
* added support for `JavaX` Plist key (fixes #9)
6+
47
### v0.8.1 (2015-03-26)
58
* Bugfix for `JVMVersion` key present but no JVMs in `/usr/libexec/java_home`
69

README.md

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@ Whilst developing some Java apps for Mac OS X I was facing the problem of suppor
1212
**Is there some difference, you might ask?** Yes, there is!
1313

1414
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/`
16-
* Oracle Java 1.7/1.8: `/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/`
15+
* Apple Java 1.5/1.6: `/System/Library/Java/JavaVirtualMachines/`
16+
* Oracle JRE 1.7/1.8: `/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/`
17+
* Oracle JDK 1.7/1.8: `/System/Library/Java/JavaVirtualMachines/`
1718

1819
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...
20+
* This is because the Apple `JavaApplicationStub` only works for Apple's Java and their `Info.plist` style to store Java properties.
21+
* To support Oracle Java 7 you would need to built a separate App package with Oracles [ANT task "Appbundler"](https://java.net/projects/appbundler).
22+
* Thus you would need the user to know which Java distribution he has installed on his Mac. Not very user friendly...
2223

2324
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...
2425

26+
4. Starting with Mac OS X 10.10 *(Yosemite)*, app packages won't open up anymore if they contain the *deprecated* Plist `Java` dictionary. This isn't confirmed by Apple, but [issue #9](https://github.com/tofi86/universalJavaApplicationStub/issues/9) leads to this assumption:
27+
* Apple seems to declare the `Java` dictionary as *deprecated* and requires the old Apple Java 6 to be installed. Otherwise the app doesn't open.
28+
* If Java 7/8 is installed, Apple doesn't accept those java versions as suitable
29+
* Apple prompts for JRE 6 download even before the `JavaApplicationStub` is executed. This is why we can't intercept at this level and need to replace the `Java` dictionary by a `JavaX` dictionary.
30+
* This requires the use of my JarBundler fork (see below for more details)
31+
2532
*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:
2633

2734
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! ;-)
@@ -71,12 +78,14 @@ What you need to do
7178
-------------------
7279

7380
Use whichever ANT task you like:
74-
* the great opensource ["Jarbundler"](http://informagen.com/JarBundler/)
75-
* my JarBundler [fork on github](https://github.com/tofi86/Jarbundler) which supports *MixedLocalization*
81+
* the opensource ["Jarbundler"](http://informagen.com/JarBundler/) *(not recommended anymore)*
82+
* my JarBundler [fork on github](https://github.com/tofi86/Jarbundler) which supports the newly introduced `JavaX` key *(recommended)*
7683
* Oracle's opensource ["Appbundler"](https://java.net/projects/appbundler)
7784
* or [*infinitekind*'s fork](https://bitbucket.org/infinitekind/appbundler/overview)
7885

79-
### JarBundler example
86+
### Original JarBundler (v2.3) example
87+
*Might lead to compatibility issues. See below for details...*
88+
8089
Just place the `universalJavaApplicationStub` from this repo in your build resources folder and link it in your ANT task (attribute `stubfile`):
8190
```XML
8291
<jarbundler
@@ -91,8 +100,32 @@ Just place the `universalJavaApplicationStub` from this repo in your build resou
91100

92101
The ANT task will care about the rest...
93102

94-
You should get a fully functional Mac Application Bundle working with both Java distributions from Apple and Oracle.
103+
You should get a functional Mac Application Bundle working with both Java distributions from Apple and Oracle **but with possible incompatibilities to Mac OS X 10.10:**
104+
105+
:exclamation: **Attention:**
106+
> Using the "old" JarBundler <= v2.3 might result in [issue #9](https://github.com/tofi86/universalJavaApplicationStub/issues/9) *(Mac OS X 10.10 asking to install deprecated Apple JRE 6 instead of using a newer Java version)*
107+
>
108+
> If you don't want to care about compatibility issues between OS X and Java versions, better use my JarBundler fork (see next example).
109+
110+
### My JarBundler fork (v2.4) example
111+
Download the latest release of my JarBundler fork [from it's github repo](https://github.com/tofi86/Jarbundler) and replace your old JarBundler library with the new one.
112+
113+
Then place the `universalJavaApplicationStub` from this repo in your build resources folder and link it in your ANT task (attribute `stubfile`). Don't forget to set the newly introduced `useJavaXKey` option:
114+
```XML
115+
<jarbundler
116+
name="Your-App"
117+
shortname="Your Application"
118+
icon="${resources.dir}/icon.icns"
119+
stubfile="${resources.dir}/universalJavaApplicationStub"
120+
useJavaXKey="true"
121+
... >
122+
123+
</jarbundler>
124+
```
125+
126+
The ANT task will care about the rest...
95127

128+
You should get a fully functional Mac Application Bundle working with both Java distributions from Apple and Oracle and all Mac OS X versions.
96129

97130
### Appbundler example
98131
Just place the `universalJavaApplicationStub` from this repo in your build resources folder and link it in your ANT task (attribute `executableName` from [*infinitekind*'s fork](https://bitbucket.org/infinitekind/appbundler/overview)):
@@ -110,7 +143,7 @@ Just place the `universalJavaApplicationStub` from this repo in your build resou
110143

111144
The ANT task will care about the rest...
112145

113-
You should get a fully functional Mac Application Bundle working with both Java distributions from Apple and Oracle.
146+
You should get a fully functional Mac Application Bundle working with both Java distributions from Apple and Oracle and all Mac OS X versions.
114147

115148

116149
Missing Features

src/universalJavaApplicationStub

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# #
1414
# @author Tobias Fischer #
1515
# @url https://github.com/tofi86/universalJavaApplicationStub #
16-
# @date 2015-03-26 #
17-
# @version 0.8.1 #
16+
# @date 2015-05-15 #
17+
# @version 0.9.0 #
1818
# #
1919
# #
2020
##################################################################################
@@ -116,6 +116,15 @@ CFBundleIconFile=`/usr/libexec/PlistBuddy -c "print :CFBundleIconFile" "${InfoPl
116116
# check Info.plist for Apple style Java keys -> if key :Java is present, parse in apple mode
117117
/usr/libexec/PlistBuddy -c "print :Java" "${InfoPlistFile}" > /dev/null 2>&1
118118
exitcode=$?
119+
JavaKey=":Java"
120+
121+
# if no :Java key is present, check Info.plist for universalJavaApplication style JavaX keys -> if key :JavaX is present, parse in apple mode
122+
if [ $exitcode -ne 0 ]; then
123+
/usr/libexec/PlistBuddy -c "print :JavaX" "${InfoPlistFile}" > /dev/null 2>&1
124+
exitcode=$?
125+
JavaKey=":JavaX"
126+
fi
127+
119128

120129
# read Info.plist in Apple style if exit code returns 0 (true, :Java key is present)
121130
if [ $exitcode -eq 0 ]; then
@@ -130,7 +139,7 @@ if [ $exitcode -eq 0 ]; then
130139

131140

132141
# read the Java WorkingDirectory
133-
JVMWorkDir=`/usr/libexec/PlistBuddy -c "print :Java:WorkingDirectory" "${InfoPlistFile}" 2> /dev/null | xargs`
142+
JVMWorkDir=`/usr/libexec/PlistBuddy -c "print ${JavaKey}:WorkingDirectory" "${InfoPlistFile}" 2> /dev/null | xargs`
134143

135144
# set Working Directory based upon Plist info
136145
if [[ ! -z ${JVMWorkDir} ]]; then
@@ -145,36 +154,36 @@ if [ $exitcode -eq 0 ]; then
145154

146155

147156
# read the MainClass name
148-
JVMMainClass=`/usr/libexec/PlistBuddy -c "print :Java:MainClass" "${InfoPlistFile}" 2> /dev/null`
157+
JVMMainClass=`/usr/libexec/PlistBuddy -c "print ${JavaKey}:MainClass" "${InfoPlistFile}" 2> /dev/null`
149158

150159
# read the JVM Options
151-
JVMOptions=`/usr/libexec/PlistBuddy -c "print :Java:Properties" "${InfoPlistFile}" 2> /dev/null | grep " =" | sed 's/^ */-D/g' | tr '\n' ' ' | sed 's/ */ /g' | sed 's/ = /=/g' | xargs`
160+
JVMOptions=`/usr/libexec/PlistBuddy -c "print ${JavaKey}:Properties" "${InfoPlistFile}" 2> /dev/null | grep " =" | sed 's/^ */-D/g' | tr '\n' ' ' | sed 's/ */ /g' | sed 's/ = /=/g' | xargs`
152161

153162
# read StartOnMainThread
154-
JVMStartOnMainThread=`/usr/libexec/PlistBuddy -c "print :Java:StartOnMainThread" "${InfoPlistFile}" 2> /dev/null`
163+
JVMStartOnMainThread=`/usr/libexec/PlistBuddy -c "print ${JavaKey}:StartOnMainThread" "${InfoPlistFile}" 2> /dev/null`
155164
if [ "${JVMStartOnMainThread}" == "true" ]; then
156165
echo ${JVMStartOnMainThread} > ~/Desktop/test.txt
157166
JVMOptions+=" -XstartOnFirstThread"
158167
fi
159168

160169
# read the ClassPath in either Array or String style
161-
JVMClassPath_RAW=`/usr/libexec/PlistBuddy -c "print :Java:ClassPath" "${InfoPlistFile}" 2> /dev/null`
170+
JVMClassPath_RAW=`/usr/libexec/PlistBuddy -c "print ${JavaKey}:ClassPath" "${InfoPlistFile}" 2> /dev/null`
162171
if [[ $JVMClassPath_RAW == *Array* ]] ; then
163-
JVMClassPath=.`/usr/libexec/PlistBuddy -c "print :Java:ClassPath" "${InfoPlistFile}" 2> /dev/null | grep " " | sed 's/^ */:/g' | tr -d '\n' | xargs`
172+
JVMClassPath=.`/usr/libexec/PlistBuddy -c "print ${JavaKey}:ClassPath" "${InfoPlistFile}" 2> /dev/null | grep " " | sed 's/^ */:/g' | tr -d '\n' | xargs`
164173
else
165174
JVMClassPath=${JVMClassPath_RAW}
166175
fi
167176
# expand variables $APP_PACKAGE, $JAVAROOT, $USER_HOME
168177
JVMClassPath=`eval "echo ${JVMClassPath}"`
169178

170179
# read the JVM Default Options
171-
JVMDefaultOptions=`/usr/libexec/PlistBuddy -c "print :Java:VMOptions" "${InfoPlistFile}" 2> /dev/null | xargs`
180+
JVMDefaultOptions=`/usr/libexec/PlistBuddy -c "print ${JavaKey}:VMOptions" "${InfoPlistFile}" 2> /dev/null | xargs`
172181

173182
# read the JVM Arguments
174-
JVMArguments=`/usr/libexec/PlistBuddy -c "print :Java:Arguments" "${InfoPlistFile}" 2> /dev/null | xargs`
183+
JVMArguments=`/usr/libexec/PlistBuddy -c "print ${JavaKey}:Arguments" "${InfoPlistFile}" 2> /dev/null | xargs`
175184

176185
# read the Java version we want to find
177-
JVMVersion=`/usr/libexec/PlistBuddy -c "print :Java:JVMVersion" "${InfoPlistFile}" 2> /dev/null | xargs`
186+
JVMVersion=`/usr/libexec/PlistBuddy -c "print ${JavaKey}:JVMVersion" "${InfoPlistFile}" 2> /dev/null | xargs`
178187

179188
# read Info.plist in Oracle style
180189
else

0 commit comments

Comments
 (0)