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

Commit

Permalink
Release version 3.0.0 (PR #60)
Browse files Browse the repository at this point in the history
Merge pull request #60 from tofi86/develop
  • Loading branch information
tofi86 authored Feb 25, 2018
2 parents f9011dd + 4eea734 commit 46b1f67
Show file tree
Hide file tree
Showing 6 changed files with 921 additions and 516 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
ChangeLog
---------

### v3.0.0 (2018-02-25)
* Completeley overhauled algorithm for JVM detection (JRE and JDK)
* JDK has no longer precedence over JRE
* All Java Virtual Machines on the system are taken into account
* See Readme section 'How the script works' for more details
* NEW special syntax in Plist key `JVMVersion` to specify a maximum JVM version requirement in addition to the minimum requirement.
* See issue #51 for examples
* Support `JVMVersion` also in Oracle PList style (#59)
* Implemented logging to `syslog` facility which can be viewed via `Console.app` (#49)
* Translation of messages to Chinese (PR #55, Thanks to @acely for his contribution)
* Added a table with 'Supported PList keys' to the Readme file
* Refactoring of functions, bash syntax, etc... (#46, #50, #56)
* Bugfix: pass JVM options with spaces correctly to the java exec call (#14)
* Bugfixes: better handling of MainClass arguments with spaces (#57, #58)
* Bugfixes: issues #47, #48, #52

### v2.1.0 (2017-07-28)
* Support for Java 9 which introduces a new version number schema (fixes #43)

Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Tobias Fischer
Copyright (c) 2014-2018 Tobias Fischer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
99 changes: 67 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,78 @@
universalJavaApplicationStub
=====================
============================

[![Current release](https://img.shields.io/github/release/tofi86/universalJavaApplicationStub.svg)](https://github.com/tofi86/universalJavaApplicationStub/releases) [![Join the chat at https://gitter.im/tofi86/universalJavaApplicationStub](https://badges.gitter.im/tofi86/universalJavaApplicationStub.svg)](https://gitter.im/tofi86/universalJavaApplicationStub?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

A BASH based *JavaApplicationStub* for Java Apps on Mac OS X that works with both Apple's and Oracle's plist format. It is released under the MIT License.
A BASH based *JavaApplicationStub* for Java Apps on Mac OS X that works with both Apple's and Oracle's plist format. It is released under the [MIT License](https://github.com/tofi86/universalJavaApplicationStub/blob/master/LICENSE).

See the [CHANGELOG](https://github.com/tofi86/universalJavaApplicationStub/blob/master/CHANGELOG.md) for a Release History and feature details.


Why
---

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.
Whilst developing some Java Apps for Mac OS X I was facing the problem of supporting two different kinds of Java versions – the old Apple versions and the new Oracle versions.

**Is there some difference, you might ask?** Yes, there is!

1. The installation directory differs:
* Apple Java 1.5/1.6: `/System/Library/Java/JavaVirtualMachines/`
* Apple Java 1.5/1.6: `/System/Library/Java/JavaVirtualMachines/` or `/Library/Java/Home/bin/java`
* Oracle JRE 1.7/1.8: `/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/`
* Oracle JDK 1.7/1.8: `/System/Library/Java/JavaVirtualMachines/`

2. Mac Apps built with tools designed for Apple's Java (like Apple's *JarBundler* or the OpenSource [ANT task "Jarbundler"](https://github.com/UltraMixer/JarBundler)) won't work on Macs with Oracle Java 7 and no Apple Java installed.
* This is because Apple's `JavaApplicationStub` only works for Apple's Java and their style to store Java properties in the `Info.plist` file.
* To support Oracle Java 7 you would need to built a separate App package with [Oracles ANT task "Appbundler"](https://java.net/projects/appbundler).
* Thus you would need the user to know which Java distribution he has installed on his Mac. Not very user friendly...
* This is because Apple's `JavaApplicationStub` only works for Apple's Java and their *style* to store Java properties in the `Info.plist` file.
* To support Oracle Java 7 you would need to built a separate App package with [Oracle's ANT task "Appbundler"](https://java.net/projects/appbundler).
* Thus you would need the user to know which Java distribution he has installed on their Mac. Not very user friendly...

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...
3. Oracle uses a different syntax to store Java properties in the applications `Info.plist` file. A Java Application packaged as a Mac App with Oracle's Appbundler also needs a different `JavaApplicationStub` and therefore won't work on systems with Apple's old Java...

4. Starting with Mac OS X 10.10 *(Yosemite)*, Java Apps won't open anymore if they contain the *deprecated* Plist dictionary `Java`. This isn't confirmed by Apple, but [issue #9](https://github.com/tofi86/universalJavaApplicationStub/issues/9) leads to this assumption:
* Apple seems to declare the `Java` dictionary as *deprecated* and ties it to the old Apple Java 6. If you have a newer version installed the app won't open.
* Apple seems to declare the `Java` dictionary as *deprecated* and ties it to their old Apple Java 6. If you have a newer Oracle Java version installed the app won't open.
* If Java 7/8 is installed, Apple doesn't accept those java versions as suitable
* 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 key.
* This requires to use the latest [JarBundler](https://github.com/UltraMixer/JarBundler/) version (see below for more details)

*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:
TL;DR: Since there is no universally working JavaApplicationStub for Java 6, 7 and above, and because Apple and Oracle really screwed things up during their Java transition phase, I was in need of a new Stub file.
And well, since I can't write such a script in C, C# or whatever fancy language, I wrote it as a Bash script. And it works!
The original script was inspired by [Ian Roberts stackoverflow answer](http://stackoverflow.com/a/17546508/1128689). Thanks, Ian!

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!

How the script works
--------------------

You don't need a native `JavaApplicationStub` file anymore. The Shell script needs to be executable – that's all.
You don't need a native `JavaApplicationStub` file anymore. The Bash script needs to be executable – that's all.

The script reads JVM properties from `Info.plist` regardless of whether it's Apple or Oracle flavour and feeds it to a commandline `java` call like the following:
The script reads JVM properties from `Info.plist` regardless of whether it's Apple or Oracle syntax and feeds them to a commandline `java` call like the following:

```Bash
# execute Java and set
# - classpath
# - dock icon
# - application name
# - JVM options
# - JVM default options
# - main class
# - JVM arguments
exec "$JAVACMD" \
# - classpath
# - splash image
# - dock icon
# - app name
# - JVM options
# - JVM default options
# - main class
# - main arguments
# - passthru arguments
exec "${JAVACMD}" \
-cp "${JVMClassPath}" \
-splash:"${ResourcesFolder}/${JVMSplashFile}" \
-Xdock:icon="${ResourcesFolder}/${CFBundleIconFile}" \
-Xdock:name="${CFBundleName}" \
${JVMOptions:+$JVMOptions }\
${JVMDefaultOptions:+$JVMDefaultOptions }\
${JVMMainClass}\
${JVMArguments:+ $JVMArguments}\
${MainArgs:+ $MainArgs}\
${ArgsPassthru:+ $ArgsPassthru}
```

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.
It sets the classpath, the dock icon, the *AboutMenuName* (as Xdock parameter) and then every *JVMOptions*, *JVMDefaultOptions* or *JVMArguments* found in the `Info.plist` file. See the table below for more supported Plist keys.

The WorkingDirectory is either retrieved from Apple's Plist key `Java/WorkingDirectory` or set to the JavaRoot directory within the app bundle.
The *WorkingDirectory* is either retrieved from Apple's Plist key `Java/WorkingDirectory` or set to the JavaRoot directory within the app bundle.

The name of the *main class* is also retrieved from `Info.plist`. If no *main class* is found, an applescript error dialog is shown and the script exits with *exit code 1*.
The name of the *main class* is also retrieved from `Info.plist`. If no *main class* is found, an AppleScript error dialog is shown and the script exits with *exit code 1*.

There is some *foo* happening to determine which Java versions are installed – here's the list in which order system properties are checked:

Expand All @@ -78,14 +83,16 @@ There is some *foo* happening to determine which Java versions are installed –
* `/usr/libexec/java_home` symlinks
* Oracle's JRE Plugin: `/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java`
* Symlink for old Apple Java: `/Library/Java/Home/bin/java`
3. If you require a specific Java version with the Plist key `JVMVersion` the script will try to find a matching JDK or JRE in all of the above locations
3. If you require a specific to-the-point Java version or a **minimum requirement** with the Plist key `JVMVersion` the script will try to find a matching JDK or JRE in all of the above locations
* if multiple matching JVM's are found, the script will pick the latest (highest version number)
* starting from version 3.0 of this script you can use a special syntax in Plist key `JVMVersion` to specify a **max requirement**. See [issue #51](https://github.com/tofi86/universalJavaApplicationStub/issues/51) for examples.

If none of these could be found or executed the script shows an applescript error dialog saying that Java needs to be installed:
If none of these can be found or executed the script shows an AppleScript error dialog saying that Java needs to be installed:

![Error Dialog No Java Found](/docs/java-error.png?raw=true)

Messages are localized and displayed either in English (Default), French or German. Language contributions are very welcome!
Messages are **localized** and displayed either in English (Default), French, German or Chinese. Language contributions are very welcome! Thank you!


What you need to do
-------------------
Expand Down Expand Up @@ -117,7 +124,7 @@ Then place the `universalJavaApplicationStub` from this repo in your build resou
</jarbundler>
```

The ANT task will care about the rest...
The ANT task will take care of all the rest... But of course you can specify more options. Please check the JarBundler docs.

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

Expand All @@ -134,20 +141,48 @@ Just place the `universalJavaApplicationStub` from this repo in your build resou
</appbundler>
```


The ANT task will care about the rest...
The ANT task will take care of all the rest... But of course you can specify more options. Please check the Appbundler docs.

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


Supported PList keys
--------------------

| Function | Apple PList key | Oracle PList key |
|---------------------------------|------------------------|-----------------------|
| **App Name** (Dock Name) | `:CFBundleName` | `:CFBundleName` |
| **App Icon** (Dock Icon) | `:CFBundleIconFile` | `:CFBundleIconFile` |
| **Working Directory** | `:Java(X):WorkingDirectory`<br/>fallback to `name.app/`<br/>support for variables `$APP_PACKAGE`, `$JAVAROOT`, `$USER_HOME` | *not supported*<br/>default: `name.app/Contents/Java/` |
| **Java Min/Max[*](https://github.com/tofi86/universalJavaApplicationStub/issues/51) Version Requirement** | `:Java(X):JVMVersion` | `:JVMVersion` |
| **Java ClassPath** (`-cp …`) | `:Java(X):ClassPath` | `:JVMClassPath` |
| **Java Main Class** | `:Java(X):MainClass` | `:JVMMainClassName` |
| **Splash Image** (`-splash:…`) | `:Java(X):SplashFile` | `:JVMSplashFile` |
| **Java VM Options** (`-X…`) | `:Java(X):VMOptions` | `:JVMDefaultOptions` |
| **`-XstartOnFirstThread`** [*](https://stackoverflow.com/questions/28149634/what-does-the-xstartonfirstthread-vm-argument-do-mean) | `:Java(X):StartOnMainThread` | *not supported* |
| **Java Properties** (`-D…`) | `:Java(X):Properties` | `:JVMOptions` |
| **Main Class Arguments** | `:Java(X):Arguments` | `:JVMArguments` |


Logging
-------

Starting with version 3.0 `universalJavaApplicationStub` logs data to the `syslog` facility which can be easily accessed with the `Console.app` utility by searching for *syslog*:

![Example log data in Console.app](/docs/ConsoleAppLogging.png?raw=true)

Log data includes debug information of the JVM search strategy, App name, language, selected JVM, WorkingDirectory and exec call.


Missing Features
----------------

At the moment, there's no support for
* required JVM architecture (like `x86_64`, etc.)
* prefer JDK over JRE or vice versa


License
-------

*universalJavaApplicationStub* is released under the MIT License.
*universalJavaApplicationStub* is released under the [MIT License](https://github.com/tofi86/universalJavaApplicationStub/blob/master/LICENSE).
Binary file added docs/ConsoleAppLogging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 46b1f67

Please sign in to comment.