Mountain Lion with Java 7 only

I performed a clean installation of Mountain Lion and installed JDK7.

java -version in Terminal returns java version "1.7.0_05" correctly, still Java Preferences and some other Java programs (such as Eclipse) result in prompts to install Java SE 6.

I can start Eclipse perfectly from the command line with Java 7.

Is there a way to get this working without having to install Java 6?


Solution 1:

JDK 7 will be installed under /Library/Java/JavaVirtualMachines/1.7.0.jdk, JDK 6 under /System/Library/Java/JavaVirtualMachines.

To trick OS X to accept Java 7 instead of proposing to install Java 6 a simple symlink is enough:

sudo mkdir /System/Library/Java/JavaVirtualMachines
sudo ln -s /Library/Java/JavaVirtualMachines/1.7.0.jdk /System/Library/Java/JavaVirtualMachines/1.6.0.jdk

Most Java Programms will run with this little hack without the need to install Java 6. OS X's Java Preferences (and maybe some others) will not as it seems to explicitly check the version of the JVM when it is started.

Solution 2:

Note: if you have something that really needs java6 and won't work with java7, then you might want to hold-off on installing java7. The reason is it might be a little tricky to try to keep both 6 and 7 on same macintosh, as the 7 pkg does some messing with some of the apple-6-java items, as detailed below. So, I'll be looking for some step-by-step instructions on keeping 6 and 7 on same mac before rolling this out... See also http://reviews.cnet.com/8301-13727_7-57533880-263/java-preferences-missing-after-latest-os-x-java-update/ on Oct 18, 2012.

DETAILS The preinstall shell script in jre-7u9-macosx-x64.dmg just removes the Apple pref-pane (as well as plug-in), without warning, below.

#!/bin/bash
PLUGIN_BASEDIR=/Library/Internet\ Plug-Ins
PLUGIN_NAME=${PLUGIN_BASEDIR}/JavaAppletPlugin.plugin
MKDIR=`which mkdir`
RM=/bin/rm
# Remove the symlink before installation forcing ystem Preferences.app to refresh its cache
PREF_PANE_NAME=JavaControlPanel.prefpane
PREF_PANE_DEST=/Library/PreferencePanes/
# Actually removes the symlink
if [[ -h "${PREF_PANE_DEST}/${PREF_PANE_NAME}" ]]; then
     ${RM} -rf "${PREF_PANE_DEST}/${PREF_PANE_NAME}"
fi
# Create the /Library/Internet Plug-Ins if not present
if [[ ! -d "${PLUGIN_BASEDIR}" ]]; then
     ${MKDIR} -p "${PLUGIN_BASEDIR}"
fi
# If Apple's plugin is present, then delete it
if [[ -h "${PLUGIN_NAME}" ]] && [[ -d "${PLUGIN_NAME}" ]]; then
    ${RM} -rf "${PLUGIN_NAME}"
fi

=== And the post install script sets up a symlink ===

#!/bin/bash
LN=`which ln`
CHOWN=`which chown`
PLUGIN_FILEPATH=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
PREF_PANE_NAME=JavaControlPanel.prefpane
PREF_PANE_SRC=/Library/Internet\ Plug-       Ins/JavaAppletPlugin.plugin/Contents/Home/lib/deploy/JavaControlPanel.prefpane
PREF_PANE_DEST=/Library/PreferencePanes/
if [ ! -h "${PREF_PANE_DEST}/${PREF_PANE_NAME}" ]; then
    ${LN} -s "${PREF_PANE_SRC}" "${PREF_PANE_DEST}"
fi
${CHOWN} -R root:wheel "${PLUGIN_FILEPATH}"