Skip to content

Instantly share code, notes, and snippets.

@justingarrick
Last active September 7, 2016 16:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justingarrick/5405921 to your computer and use it in GitHub Desktop.
Save justingarrick/5405921 to your computer and use it in GitHub Desktop.
OS X Java7 & Eclipse Setup
1.* Delete all traces of Java 6. Look under /Library/Java/JavaVirtualMachines and /System/Library/Java/JavaVirtualMachines
2. Install JDK7 via the .dmg from Oracle, it should install to /Library/Java/JavaVirtualMachines
3. Symlink JDK7 to JDK6 to "trick" OS X into thinking we have Java 6 installed for applications that require it:
$ sudo mkdir /System/Library/Java/JavaVirtualMachines
$ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk /System/Library/Java/JavaVirtualMachines/1.6.0.jdk
4.** Set JAVA_HOME. You can't just set this in your ~/.bashenv or ~/.zshenv files, because the m2e plugin in Eclipse isn't aware of those unless you start Eclipse from the command line. You need to add it to /etc/launchd.conf:
$ sudo touch /etc/launchd.conf
$ sudo printf "setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home" >> /etc/launchd.conf
$ sudo grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
5. Install Eclipse (unzip, drag eclipse folder to /Applications
6. In Finder, open /Applications/eclipse, right click on Eclipse.app, select Show Package Contents. eclipse.ini is under Contents. Edit this using whatever settings you prefer (e.g. https://gist.github.com/justingarrick/2588828). Note that the -vm argument here will have no effect. In Contents/Info.plist, there is a -vm key you can supposedly change to start Eclipse with a particular VM, but this didn't work for me.
* One interesting side note is that since you have a symlink from 1.7 -> 1.6, OS X thinks you have 1.6 installed, so it will try to deliver 1.6 updates to you. If you download these updates, it will place them in the 1.6 symlink, which will overwrite your 1.7 install. I suspect this is because of my ghetto version of step 1. Doing something like this may prevent this problem: http://stikine.wordpress.com/2012/03/02/howto-remove-java/
** Also note that newer versions of OS X come with a java_home utility, which you should use for determining the path to java when setting env vars in other areas, e.g. export JAVA_HOME=$(/usr/libexec/java_home)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment