4

I got an Java application that does run under Java 1.8 without problems when I start its JAR directly. However on my Mac the JAR is wrapped within an app that demands me to install Java 1.6 -- which I really do not want to do!

So I'm searching the point within the app package where I could configure that my App shall use the installed Java 1.8

Changing property InfoDictionary version within Contents/Info.plist to 8.0 will not help.

Is this possible at all or do I need to build a complete new App Package? In case of the later, which tool would be best to do this for a bunch of applications?

8
  • Is the app a Java application on its own, or is it called Tom within another app? If it's a Java app on its own, you can point a specific Java version at it, otherwise you'll need to specify a global Java version any time you want to open that app. Sep 1, 2015 at 23:51
  • @agentroadkill: Originally it's an application of its own, being deployed as a JAR file on every other platform. For MacOS it is packaged within an APP package. If you select "show package content" in it you will find some meta data, Info.plist and the JAR itself. I can start this JAR directly though.
    – Seven
    Sep 2, 2015 at 18:50
  • @agentroadkill: So, could you please elaborate a bit on how to specify my Java version to all the apps?
    – Seven
    Sep 2, 2015 at 18:58
  • Here is the SuperUser post specifying what you're looking to do. I'll elaborate more in an answer below. Sep 2, 2015 at 19:02
  • I think this answer may complete this thread: stackoverflow.com/a/15379462/335478
    – Seven
    Oct 14, 2015 at 15:59

4 Answers 4

4

Thanks to a post on SuperUser, this appears to be fairly straightforward. It appears that different Java versions can be called from Apple's own JRE:

/usr/libexec/java_home -v 1.6.0 --exec <Java command>

My understanding is that this doesn't actually provide a different JRE, but simply causes the installed JRE to identify itself as the called version, and implements any minor differences between versions. Others should definitely correct me if this is not the case.

For your purposes, this would be

/usr/libexec/java_home -v 1.6.0 --exec java -jar <yourJarHere>.jar

The above linked post also points out that you can edit the file called /Applications/yourApp.app/Contents/MacOS/yourApp to use the correct command so you don't need to re-type that or remember every time.

All this courtesy Geff

2
  • All it does is run the java defined with the -v parameter
    – mmmmmm
    Oct 15, 2015 at 14:44
  • Right-the issue was that the app wanted a different version of the JRE. This causes the Apple-supplied JRE to identify itself as the required one, and provides the expected functions of that Java version Oct 15, 2015 at 15:16
4

It seems that Oracle could have fixed this. But didn't ...

So I got it working now doing this: (All credits go to: https://oliverdowling.com.au/2014/03/28/java-se-8-on-mac-os-x)

I assume you got the latest JDK installed (currently 1.8.0_60, please adjust this in future)

Change content of Info.plist:

Open Terminal and issue this command

sudo nano /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Info.plist

Look for key JVMCapabilities and change it to this:

<key>JVMCapabilities</key>
<array>
    <string>CommandLine</string>
    <string>JNI</string>
    <string>BundledApp</string>
</array>

Add a symlink for libjvm.dylib and libserver.dylib:

Open Terminal and issue these two commands:

sudo mkdir -p /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bundle/Libraries
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/server/libjvm.dylib /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bundle/Libraries/libserver.dylib
3
  • 1
    What does this chnage do?
    – mmmmmm
    Oct 15, 2015 at 14:58
  • @Mark This change allows the JVM to be run not only from the command line, but also the Java Native Interface and bundled apps. However, you may find that it will still be unable to find libjvm.dylib and libserver.dylib which is fixed with the symlinks.
    – spex
    Oct 5, 2018 at 17:47
  • this is a great answer but how do you apply this to JRE instead of a JDK? I found the equivalent for the symlinking under /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/ but there is no Info.plist that contains a JVMCapabilities entry.
    – tatsu
    Jun 5, 2019 at 9:49
3

This might help jump-start finding an answer. Recalling that PyCharm.app does something similar, here is an extract from the applications Info.plist file (watch the …snip… lines in there):

…snip…
<key>JVMOptions</key>
<dict>
  …snip…
  <key>JVMVersion</key>
  <!-- string>1.6*,1.7+</string -->
  <string>1.7+</string>
  …snip…
</dict>
…snip…

Also, the PaperCut Client application (PCClient) uses some simliar items in its Info.plist:

<plist version="1.0">
  <dict>
    …snip…
    <key>CFBundleExecutable</key>
    <string>JavaAppLauncher</string>
    <key>JVMRuntime</key>
    <string>jre</string>
    <key>JVMMainClassName</key>
    <string>biz.papercut.pcng.client.uit.UserClient</string>
    <key>JVMOptions</key>
    <array>
      <string>-Dclient.home=$APP_ROOT/Contents/Resources/</string>
      <string>-Dcom.apple.macos.useScreenMenuBar=true</string>
      <string>-Xmx256m</string>
      <!-- Workaround since the icon parameter for bundleapp doesn't work -->
      <string>-Xdock:icon=$APP_ROOT/Contents/Resources/client-icon.icns</string>
    </array>
    <key>JVMArguments</key>
    <array/>
  </dict>
</plist>

Again, these are parts of different Info.plist files so they might not work as straight copy-and-paste. However, both apps work on OS X, so these keys/values might help you narrow down to a working solution.

Both apps seem to have a slightly different way of doing things. PCClient.app appears to include it's own version of Java, whereas PyCharm relies on what’s installed on OS X.

1
  • Thank you, that's exactly the place where I thought one should be able to state the minimal JRE required... However, none of these settings had an effect. I still get a dialog asking to install JRE 1.6. I think it also depends on the JavaAppLauncher that is actually started up, which will in turn ask for a JRE 1.6
    – Seven
    Sep 2, 2015 at 18:56
0

for details, please check/read this section "OPTIONAL / EXTRA : Setup Specific Java ENV-VAR" (this section is in bottomside) of this answer, pls also see this answer.

Summary:

  1. Obtain Legacy Java 8 (JDK, 1.8, it includes JRE) binary (that is optimized for macOS) (and it also includes Src-code), from Oracle site & install it, (Oracle based Java is free only-for Personal usage, not-free for Commercial usage & not-free if you want to distribute JRE ) . ( OpenJDK based Legacy Java 8 (1.8) Src-code is available in OpenJDK.java.net site, for those, who want to compile it & build their own binary . OpenJDK (includes JRE) v9 (1.9) & above are available as macOS optimized binary form in OpenJDK archive-site/page . OpenJDK based Java is free for any Commercial usage & also free for Personal usage. )
  2. Setup these specific ENV VARs: JAVA_HOME & PATH, only for a specific App, before running it, by using a shell script:
    ( do not type the word 'cmd:', when you copy/type a command from here )
  • Run this command-set to create a shell-script file with a header line:
    cmd: sb='#!/bin/bash' ; echo "$sb" > ~/java-based-APP-name.sh ; unset sb;
    ( change the "java-based-APP-name" into your actual target App name )
  • edit that shell script file by using nano:
    cmd: nano ~/java-based-APP-name.sh
    • 1st line must be #!/bin/bash to use it as "BASH" shell script, then add below 5-lines:
      export JAVA_HOME=$(/usr/libexec/java_home --version 1.8);
      export PATH="$JAVA_HOME/bin:$PATH";
      # $JAVA_HOME/bin/java -jar executableJarAppName.jar
      # $JAVA_HOME/bin/java -cp jarAppName.jar <full-path-of-main-class>
      "/Applications/java-based-APP-name.app/Contents/MacOS/java-based-APP-name"
  • Save "~/java-based-APP-name.sh" & exit out from nano . ( Nano )
    ( Note: if a macOS app's name is "My MacApp.app", then it must have an executable file with same name here: "My MacApp.app/Contents/MacOS/My MacApp" . So above example script is using that example executable )
  • And set 'execute' permission bit: cmd: chmod +x ~/java-based-APP-name.sh
  1. Now you can run the App by using the shell-script: cmd: ~/java-based-APP-name.sh
    ( that App will have access to Java 8 (1.8) which you've installed, & which you've specified in the shell script . You can also create a shortcut/link for that shell-script & place the link inside the /Applications , so that you can see an Icon & just click that to run the target App. )

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .