Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

universalJavaApplicationStub - an alternative Application launcher script for Java based macOS Apps that works with both Apple's and Oracle's PList format and supports the old Apple Java 6 as well as all the latest Oracle/OpenJDK/Adopt/Corretto JRE's/JDK's. Plus it supports drag&drop to the Dock icon 🎉

License

NotificationsYou must be signed in to change notification settings

tofi86/universalJavaApplicationStub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tests and ShellcheckCurrent release

A BASH basedlauncher stub for Java based macOS Apps that works with both Apple's and Oracle's plist format. It is released under theMIT License.

📃 🔄 See theCHANGELOG for a Release History and feature details.

🐛 🔥 ReportIssues at theGitHub Issues Page.

🤔 ❓ If you have ageneral question about how a feature works or would like toshare an idea or ausecase for this project, then please use theGitHub Discussions Page.

Why

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/ 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/
  1. Mac Apps built with tools designed for Apple's Java (like Apple'sJarBundler or the OpenSourceANT task "Jarbundler") won't work on Macs with Oracle Java 7 and no Apple Java installed.
  • This is because Apple'sJavaApplicationStub only works for Apple's Java and theirstyle to store Java properties in theInfo.plist file.
  • To support Oracle Java 7 you would need to built a separate App package withOracle's ANT task "Appbundler".
  • Thus you would need the user to know which Java distribution he has installed on their Mac. Not very user friendly...
  1. Oracle uses a different syntax to store Java properties in the applicationsInfo.plist file. A Java Application packaged as a Mac App with Oracle's Appbundler also needs a differentJavaApplicationStub and therefore won't work on systems with Apple's old Java...

  2. Starting with Mac OS X 10.10(Yosemite), Java Apps won't open anymore if they contain thedeprecated Plist dictionaryJava. This isn't confirmed by Apple, butissue #9 leads to this assumption:

  • Apple seems to declare theJava dictionary asdeprecated 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 theJavaApplicationStub is executed. This is why we can't intercept at this level and need to replace theJava dictionary by aJavaX dictionary key.
  • This requires to use the latestJarBundler version (see below for more details)

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 byIan Roberts stackoverflow answer. Thanks, Ian!

How the script works

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

The script reads JVM properties fromInfo.plist regardless of whether it's Apple or Oracle syntax and passes them to aexec java call like the following simplified:

# execute Java and set# - classpath# - splash image# - dock icon# - app name# - JVM options / properties (-D)# - JVM default options (-X)# - main class# - main class arguments# - passthrough arguments from Terminal or Drag'n'Drop to Finder iconexec"${JAVACMD}" \    -cp"${JVMClassPath}" \    -splash:"${ResourcesFolder}/${JVMSplashFile}" \    -Xdock:icon="${ResourcesFolder}/${CFBundleIconFile}" \    -Xdock:name="${CFBundleName}" \${JVMOptions} \${JVMDefaultOptions} \${JVMMainClass} \${MainArgsArr} \${ArgsPassthru}

It sets the classpath, the dock icon, theAboutMenuName (as Xdock parameter) and then everyJVMOptions,JVMDefaultOptions orJVMArguments found in theInfo.plist file. See the table below for more supported Plist keys.

TheWorkingDirectory is either retrieved from Apple's Plist keyJava/WorkingDirectory or set to the JavaRoot directory within the app bundle.

The name of themain class is also retrieved fromInfo.plist. If nomain class is found, an AppleScript error dialog is shown and the script exits withexit code 1.

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

  1. System variable$JAVA_HOME
  1. Highest available Java version(Java 8 trumps 7) found in one of these locations:
  • /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
  1. If you require a specific to-the-point Java version or aminimum requirement with the Plist keyJVMVersion 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 keyJVMVersion to specify amax requirement. Seeissue #51 for examples.

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

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

What you need to do

Use whichever ANT task you like:

Or build the App bundle statically from scratch...

JarBundler (≥ v3.3) example

Download the latest JarBundler releasefrom its github repo.

Attention:

Using an older version of JarBundler (e.g.old JarBundler ≤ v2.3 ornew JarBundler ≤ v3.2) might result inissue #9(Mac OS X 10.10 asking to install deprecated Apple JRE 6 instead of using a newer Java version)

If you don't want to care about compatibility issues between OS X and Java versions, make sure to use thelatest JarBundler version ≥ 3.3

Then place theuniversalJavaApplicationStub from this repo in your build resources folder and link it in your ANT task (attributestubfile). Don't forget to set the newly introduceduseJavaXKey option for compatibility:

<jarbundlername="Your-App"shortname="Your Application"icon="${resources.dir}/icon.icns"stubfile="${resources.dir}/universalJavaApplicationStub"useJavaXKey="true"... ></jarbundler>

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.

Appbundler example

Just place theuniversalJavaApplicationStub from this repo in your build resources folder and link it in your ANT task (attributeexecutableName frominfinitekind fork):

<appbundlername="Your-App"displayname="Your Application"icon="${resources.dir}/icon.icns"executableName="${resources.dir}/universalJavaApplicationStub"... ></appbundler>

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

FunctionApple PList keyOracle PList key
App Name (Dock Name):CFBundleName:CFBundleName
App Icon (Dock Icon):CFBundleIconFile:CFBundleIconFile
Working Directory🌟:Java(X):WorkingDirectory
fallback to `name.app/
not supported
default:name.app/Contents/Java/
Java Min/Max 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:Java(X):StartOnMainThreadnot supported
Java Properties (-D…)🌟:Java(X):Properties:JVMOptions
Main Class Arguments🌟:Java(X):Arguments:JVMArguments

🌟 Variable placeholders$APP_PACKAGE,$APP_ROOT,$JAVAROOT,$USER_HOME get expanded in these contexts.

Specify min/max Java requirement

Since v3.0 (#51)

UseJava(X):JVMVersion (Apple style) or:JVMVersion (Oracle style) with the following values:

  • 1.8 or1.8* for Java 8
  • 1.8+ for Java 8 or higher
  • 1.7;1.8* for Java 7 or 8
  • 1.8;9.0 for Java 8* up to exactly 9.0 (but not 9.0.*)
  • 1.8;9.0* for Java 8* and 9.0.* but not 9.1.*

Bundle a JRE/JDK with your app

You can use the Plist keyLSEnvironment to export and set the$JAVA_HOME environment variable relative to your App's root directory:

<key>LSEnvironment</key><dict>    <key>JAVA_HOME</key>    <string>Contents/Frameworks/jdk8u232-b09-jre/Contents/Home</string><dict>

Use a compiled binary for macOS 10.15 and above

Starting with macOS 10.15 Apple by default prevents access toProtected Resources like the user'sDownload,Documents orDesktop folders and shows a security dialog which the user has to accept before access is granted.

When usingjavax.swing.JFileChooser in your application, which supports these kinds of security dialogs (interestinglyjava.awt.FileDialog does not!), you should use a compiled binary of theuniversalJavaApplicationStub script instead of the plain bash script. Seeissue #85 for more details.

Starting with version 3.1.0 we provide pre-built binaries on theReleases page which are automatically compiled withshc via GitHub Actions CI.

Additionaly we recommend you setUsage Description Plist keys as described further below.

Recommended additional Plist keys

NSAppleEventsUsageDescription

Starting with Mac OS 10.14 users may be confronted with an additional system security dialog before any warning dialog of this stub is shown. Seeissue #77 for more details.

This happens because the warning dialogs of this launcher stub are displayed with AppleScript.

It's recommended to at least set the following Plist key in order to display a descriptive message to the user, why he should grant the app system access:

<key>NSAppleEventsUsageDescription</key><string>There was an error while launching the application. Please click OK to display a dialog with more information or cancel and view the syslog for details.</string>

Access to "Protected Resources"

If your app requires access toProtected Resources like the user'sDownload,Documents orDesktop folders, there area couple more properties to add in your Plist file for setting aUsage Description:

This may be extra important when usingjavax.swing.JFileChooser in your application. Seeissue #85 for more details.

Logging

Starting with version 3.0universalJavaApplicationStub logs data to thesyslog facility which can be easily accessed with theConsole.app utility by searching forsyslog:

Example log data in Console.app

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 (likex86_64, etc.)
  • prefer JDK over JRE or vice versa

License

universalJavaApplicationStub is released under theMIT License.

About

universalJavaApplicationStub - an alternative Application launcher script for Java based macOS Apps that works with both Apple's and Oracle's PList format and supports the old Apple Java 6 as well as all the latest Oracle/OpenJDK/Adopt/Corretto JRE's/JDK's. Plus it supports drag&drop to the Dock icon 🎉

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors14

Languages


[8]ページ先頭

©2009-2025 Movatter.jp