Java 1.5 for OS X Mountain Lion

2012.08.17 23:06 MDT

There's lots of information on the internet about getting a Java 1.5 JRE running in Snow Leopard, but if you update to OS X Mountain Lion you have to jump thru a few more hoops make it work. If you followed the previous instructions for Java 1.5 for OS X Lion then these instructions are almost identical with a small change to step 11 and 12, and they will continue to work beautifully for your OS X Lion installs. Here's what you need to do to make it all work in OS X Mountain Lion:

NOTE: To run Zend Studio 5.x in Lion or Mountain Lion, there's a better solution...
Go to Zend Studio 5.x for OS X Mountain Lion (Java SE 6).

Before we begin... if after reading this you hyperventilate or feel woozy, Brice Dutheil has created a very cool bash script that will perform all these steps for you. I haven't tried it personally but a quick sanity check of the code makes me think it would work as advertised. There's also some useful tricks in there, like mounting the dmg then extracting the pkg and payload data from the command line. All you isn't-there-just-something-I-could-run-that-would-just-do-it-all-for-me types should all be sending Brice your extra Amazon promo codes or something. However, those of you who like to get your figers dirty, read on...

Also, I had one report that in step 18 the /System/Library/Java/JavaVirtualMachines directory did not exist in their install, but /Library/Java/JavaVirtualMachines did. According to the report, using that direcory still resulted in a successful Java 1.5 VM. After installing the Apple supplied Java Runtime, choose the directory where 1.6.0.jdk is for step 18. Mine is in the System JVM directory. Thanks to Dakshinamurthy Karra.

  1. As a prerequisite, you should have installed the Apple supplied Java Runtime for your OS X install. Running any Java application (like Java Preferences.app in your Utilities folder) for the first time will prompt you to install it if you haven't already.
  2. Download the official Java package from Apple, Java for Mac OS X 10.5 Update 10 and mount the disk image.
  3. Register a copy (you'll be happy you did) of CharlesSoft's must-have utility Pacifist to view the package contents within.
  4. Open a terminal and get a root shell:

    $ sudo -s
  5. Change to the JavaVM Framework Versions directory:

    # cd /System/Library/Frameworks/JavaVM.framework/Versions
  6. Remove the 2 symlinks for Java 1.5:

    # pwd
    /System/Library/Frameworks/JavaVM.framework/Versions
    # rm -i 1.5
    remove 1.5? y
    # rm -i 1.5.0
    remove 1.5.0? y
  7. Use Pacifist to open JavaForMacOSX10.5Update10.pkg in the disk image you downloaded in step 1 and navigate to System > Library > Frameworks > JavaVM.framework > Versions
  8. Select 1.5.0, right-click, and choose Install to Default Location. When asked, Use Administrator Privileges.
  9. Back in the terminal...

    • OS X Lion: rename the newly installed 1.5.0 directory to 1.5.0_30:

      # pwd
      /System/Library/Frameworks/JavaVM.framework/Versions
      # mv -v 1.5.0 1.5.0_30
      1.5.0 -> 1.5.0_30
    • OS X Mountain Lion: copy only the 64-bit files from the newly installed 1.5.0 directory to 1.5.0_30 and if successful, remove the 1.5.0 directory:

      # pwd
      /System/Library/Frameworks/JavaVM.framework/Versions
      # ditto -v --arch x86_64 1.5.0 1.5.0_30 && rm -rf 1.5.0
      Copying 1.5.0_30 [x86_64]
  10. Create symbolic links to ./1.5.0_30 for 1.5 and 1.5.0:

    # pwd
    /System/Library/Frameworks/JavaVM.framework/Versions
    # ln -sivh ./1.5.0_30 1.5
    1.5 -> ./1.5.0_30
    # ln -sivh ./1.5.0_30 1.5.0
    1.5.0 -> ./1.5.0_30
    # ls -Fld 1.5*
    lrwxr-xr-x 1 root wheel 10 Jul 21 14:28 1.5@ -> ./1.5.0_30
    lrwxr-xr-x 1 root wheel 10 Jul 21 14:29 1.5.0@ -> ./1.5.0_30
    drwxr-xr-x 9 root wheel 306 Jul 21 14:26 1.5.0_30/
  11. Change into 1.5.0_30 and use vi (or nano) to edit ./Resources/Info.plist:

    # cd 1.5.0_30
    # pwd
    /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0_30
    # vi ./Resources/Info.plist
  12. Edit the value for key JVMMaximumFrameworkVersion:

    <key>JVMMaximumFrameworkVersion</key>
    <string>*.*.*</string>
  13. Edit the value for key JVMMaximumSystemVersion:

    <key>JVMMaximumSystemVersion</key>
    <string>10.*.*</string>
  14. Add a new key and string value for CFBundleExecutable as the first element of the main <dict> node:

    <plist version="1.0">
    <dict>
      <key>CFBundleExecutable</key>
      <string>libjava.jnilib</string>
  15. Save and exit your editor.
  16. Create a symbolic link to ./Resources/Info.plist in the 1.5.0_30 directory:

    # pwd
    /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0_30
    # ln -siv ./Resources/Info.plist .
    ./Info.plist -> ./Resources/Info.plist
    # ls -Fl Info.plist
    lrwxr-xr-x 1 root wheel 22 Jul 21 14:01 Info.plist@ -> ./Resources/Info.plist
  17. Create a directory ./MacOS in the 1.5.0_30 directory change to it:

    # pwd
    /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0_30
    # mkdir -v ./MacOS
    mkdir: created directory 'MacOS'
    # cd ./MacOS
  18. Create a symbolic link to ../Libraries/libjava.jnilib in the MacOS directory:

    # pwd
    /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0_30/MacOS
    # ln -siv ../Libraries/libjava.jnilib .
    ./libjava.jnilib -> ../Libraries/libjava.jnilib
    # ls -Fl libjava.jnilib
    lrwxr-xr-x 1 root wheel 27 Jul 21 14:11 libjava.jnilib@ -> ../Libraries/libjava.jnilib
  19. Change to the Java Virtual Machines directory and create a 1.5.0 directory:

    # cd /System/Library/Java/JavaVirtualMachines
    # pwd
    /System/Library/Java/JavaVirtualMachines
    # mkdir -v 1.5.0
    mkdir: created directory '1.5.0'
    # ls -Fl
    drwxr-xr-x 2 root wheel 68 Jul 21 14:40 1.5.0/
    drwxr-xr-x 3 root wheel 102 Jun 29 00:26 1.6.0.jdk/
  20. Change to the 1.5.0 directory and Create a symbolic to 1.5.0_30 called Contents:

    # cd 1.5.0
    # pwd
    /System/Library/Java/JavaVirtualMachines/1.5.0
    # ln -sivh /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0_30 ./Contents
    ./Contents -> /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0_30
    # ls -Fl
    lrwxr-xr-x 1 root wheel 61 Jul 21 16:40 Contents@ -> /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0_30
  21. Run Java Preferences.app in your Utilities folder and check for Java 1.5. If it doesn't show, go back and double check your work.

Questions or comments to blog [at] s [hyphen] seven [dot] net.

A few of you asked, so here you go...

(all donations will be use to buy coffee)