How does IntelliJ determine which version of Java to run under?

I am on a Mac (Mountain Lion) and I have Java 1.6 Update 33 installed (latest update from apple); however, IntelliJ is running under Java 1.6 update 27 (as indicated on the about screen).

Doing a little bit of poking around it looks like in Update 33 Apple changed the install location of Java. Looks like it used to install in /Library/Java/JavaVirtualMachines and now it installs in /System/Library/Java/JavaVirtualMachines.

IntelliJ is choosing 1.6.0_27 in /Library/Java/JavaVirtualMachines. Is there anyway to get it to choose Update 33 in /System/Library/Java/JavaVirtualMachines?

(note this is only for the version IntelliJ uses to run, I have no issue with configuring and using different SDK's for my projects)

mjparme:/Library/Java/JavaVirtualMachines:189> ls -l
total 0
drwxr-xr-x  3 root  wheel  102 Oct  7  2011 1.6.0_26-b03-383.jdk
drwxr-xr-x  3 root  wheel  102 Sep 22  2011 1.6.0_27-b07-395.jdk
drwxrwxr-x  3 root  wheel  102 Feb 23 13:03 1.7.0.jdk
drwxr-xr-x  3 root  wheel  102 Aug 16 11:33 jdk1.7.0_06.jdk

The 1.6.0.jdk directory here is Update 33:

mjparme:/System/Library/Java/JavaVirtualMachines:191> ls -l
total 0
drwxr-xr-x  3 root  wheel  102 Aug 16 11:10 1.5.0
drwxr-xr-x  3 root  wheel  102 Jun  4 16:45 1.6.0.jdk


Hmm.. that's interesting. I'm running ML as well, but JDK (update 33) is located in /LibraryJava/JavaVirtualMachines.

DanBarMBP:~ danbar$ cd /Library/Java/JavaVirtualMachines/
DanBarMBP:JavaVirtualMachines danbar$ ls -l
total 0
drwxr-xr-x  3 root  wheel  102 Jun  4 23:40 1.6.0_33-b03-424.jdk
DanBarMBP:JavaVirtualMachines danbar$ cd /System/Library/Java/
DanBarMBP:Java danbar$ ls -l
total 0
drwxr-xr-x  5 root  wheel  170 Jul 27 20:34 Extensions
drwxr-xr-x  4 root  wheel  136 Jul 27 20:34 Support

I'm not an expert on IDEA configuration, but try to:
(a) set IDEA_JDK variable to JDK location you want to run IDEA with, i.e. /Library/Java/JavaVirtualMachines/1.6.0_33-b03-424.jdk/Contents/Home
- or -
(b) go to "Java Preferences" and drag desired JRE version to the top of the list

PS. You can quickly check what's your default version of JRE using command: "java -version" (shows version) or "echo $(/usr/libexec/java_home)" (shows location).


Dragging Update 33 to the top of Java Preferences did the trick. java -version was always showing Update 33, but that is because I had JAVA_HOME pointing at the 1.6 update 33 directory. So it appears IntelliJ uses Java Preferences to determine which one to use. At one time a few version ago you could set it in Info.plist. That doesn't seem to work now.

Using update 27 wasn't causing any issues, I was just curious.


On windows, the search order for a JRE to use is:

  1. IDEA_JDK env variable
  2. jre directory in the IntelliJ IDEA installation location
  3. JDK_HOME env variable
  4. JAVA_HOME env variable

On linux, the load order is:

  1. IDEA_JDK env variable
  2. JDK_HOME env variable
  3. JAVA_HOME env variable
  4. jre directory in the IntelliJ IDEA installation location

For windows, in the the bin directory of the IntelliJ IDEA installation directory, there is an idea.bat script that has the logic for setting the necessary properties including the JDK to use. Linux has an script. I would suspect that Mac OS has a similar script. But in the end, the easiest way to control the version of Java IntelliJ IDEA uses is to set the IDEA_JDK environment variable.


Please sign in to leave a comment.