I tried running an app that requires Java, but received an alert saying “you need a Java SE 6 runtime. Would you like to install one now?”
I did not want to install an old version of Java, but it turns out the latest release doesn’t work out of the box.
Update Oct 2015
El Capitan has been released, and some things have changed. I’ve created a new post with instructions for installing just the JRE, which should be fine for most users. I also created a new post with instructions for installing the JDK which is slightly simpler, but contains unnecessary files for users not doing Java software development.
I went to the Oracle Java downloads page and downloaded JDK 8 (it is possible to install the JRE, but not with the installer provided by Oracle). The installation process is straight forward, and I confirmed Java SE 8 was installed correctly, but I still received the alert. Note that the version referenced throughout this post (1.8.0_45) may not be current as you are reading this. You may need to update the version numbers to match the latest Java release.
$ java -version java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
I found the answer on StackOverflow, apparently Java isn’t letting OS X know that it can open bundled apps. The solution is to edit
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Info.plist and change:
<key>JVMCapabilities</key> <array> <string>CommandLine</string> </array>
<key>JVMCapabilities</key> <array> <string>CommandLine</string> <string>JNI</string> <string>BundledApp</string> </array>
This got rid of the alert, but despite being able to successfully run my jar from the command line, my app didn’t start. I then tried opening the app from Terminal by running the Java application loader included in my app:
$ MyApp.app/Contents/MacOS/JavaApplicationStub JavaVM: Failed to load JVM: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bundle/Libraries/libserver.dylib JavaVM: Failed to load JVM: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bundle/Libraries/libserver.dylib JavaVM FATAL: Failed to load the jvm library. [JavaAppLauncher Error] JNI_CreateJavaVM() failed, error: -1
libserver.dylib didn’t exist, so after finding the answer on Google Code (which happened to also address the previous issue), I created the directories and created a link to
libjvm.dylib with the following commands. Enter your password if/when prompted.
sudo mkdir -p /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bundle/Libraries sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/server/libjvm.dylib /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bundle/Libraries/libserver.dylib
The app can now be opened just like any other, as expected.
Note that I am using Mac OS X
Mavericks 10.9.2 Yosemite 10.10.3 and JDK 8 Update 45, not just the JRE. The process should be the same for the JRE and newer Java versions, with minor changes to the folder names (Update 45 JDK has “_45” in the paths above), but I did not test any other option.
Update Dec 2014:
- This has continued to work after upgrading to Mac OS X Yosemite 10.10.1.
A security vulnerability (POODLE) has been found since the last Java release, so I recommend disabling SSL v3.0.The latest release does this by default. I personally recommend disabling Applets and WebStart (either by removing them from JVMCapabilities in the Info.plist mentioned above, or through the Java Control Panel).I removed this from my post.
Update Jan 2015:
A commenter, eric3k, has told me that creating two empty folders may also fix this issue. If the above does not work, you might want to give that a try. The two folders are:
You can create these with the following commands:
sudo mkdir -p /System/Library/Java/JavaVirtualMachines/1.6.0.jdk sudo mkdir -p /System/Library/Java/Support/Deploy.bundle
Update Mar 2015:
Beware! The latest JRE installer from Oracle includes adware. Oracle recently released Java 8 Update 45, and added an Ask.com browser toolbar in the installer. At time of writing, it is Step 5 on the Java.com Mac installation help page. I highly recommend deselecting the option to install this additional piece of software. If you accidentally install it, you should uninstall the extension from any and all browsers. You will also have to change your homepage back away from Ask.com.
The JRE installer from Oracle only actually installs the web plugin. If you actually want just the JRE, you will need to download the
.tar.gz version from the downloads page, unzip it, and move the unzipped folder (
/Library/Java/JavaVirtualMachines/ and follow the above instructions. However, you will have to modify the commands slightly, changing “
jdk” to “
jre” and removing “
jre/” from the
Update Jun 2015 regarding El Capitan:
- Mac OS X 10.11 El Capitan is currently a Developer Preview. I would recommend against running this as your main operating system.
- I’ve read that Java 6 is temporarily unavailable in El Capitan.
- A new mode called “Rootless” is enabled by default, which will prevent you from modifying System files. You can disable it by opening Terminal, running
sudo nvram boot-args=”rootless=0″
and restarting your computer.
- You can disable Rootless mode later with:
sudo nvram -d boot-args