3

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?

  • 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. – agentroadkill Sep 1 '15 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 '15 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 '15 at 18:58
  • Here is the SuperUser post specifying what you're looking to do. I'll elaborate more in an answer below. – agentroadkill Sep 2 '15 at 19:02
  • I think this answer may complete this thread: stackoverflow.com/a/15379462/335478 – Seven Oct 14 '15 at 15:59
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.

  • 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 '15 at 18:56
3

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
  • 1
    What does this chnage do? – Mark Oct 15 '15 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 '18 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 at 9:49
1

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

  • All it does is run the java defined with the -v parameter – Mark Oct 15 '15 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 – agentroadkill Oct 15 '15 at 15:16

You must log in to answer this question.

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