Java 1.5 for OS X Lion

2011.07.21 17:10 MDT

UPDATE: If you're here because you want to run Zend Studio 5.x in Lion, I have a better solution for you.
Go to Zend Studio 5.x for OS X Lion (Java SE 6).

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 Lion you have to jump thru a few more hoops make it work. Much of the unchanged Snow Leopard instructions below were borrowed from chxo internets. Here's what you need to do to make it all work in OS X Lion:

UPDATE: 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...

UPDATE: I've had one report that in step 18 the /System/Library/Java/JavaVirtualMachines directory did not exist in their Lion install, but /Library/Java/JavaVirtualMachines did. According to the report, using that direcory still resulted in a successful Java 1.5 VM. It wasn't specified whether theirs was a fresh Lion install or an upgrade from Snow Leopard nor was it specified whether the default Java SE 6 for Lion was installed. I have both directories, but the the 1.6.0.jdk is in the System JVM directory. Thanks to Dakshinamurthy Karra.

  1. Download the official Java package from Apple, Java for Mac OS X 10.5 Update 10 and mount the disk image.
  2. Register a copy (you'll be happy you did) of CharlesSoft's must-have utility Pacifist to view the package contents within.
  3. Open a terminal and get a root shell:

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

    # cd /System/Library/Frameworks/JavaVM.framework/Versions
  5. 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
  6. 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
  7. Select 1.5.0, right-click, and choose Install to Default Location. When asked, Use Administrator Privileges.
  8. Back in the terminal, 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
  9. 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/
  10. 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
  11. Edit the value for key JVMMaximumFrameworkVersion:

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

    <key>JVMMaximumSystemVersion</key>
    <string>10.7.*</string>
  13. 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>
  14. Save and exit your editor.
  15. 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
  16. 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
  17. 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
  18. 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/
  19. 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
  20. 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.