In some terms this is misunderstanding, but I hope it gets clearer soon:
The Apple packaged JRE/JDK is always installed in /System/Library/Frameworks/JavaVM.framework/Versions/Current
, where "Current" is a link pointing to the actual version. Therefore, you can have multiple versions installed and use multiple versions in Xcode or other IDE.
Oracle and its installers install their JDK/JRE in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
for the webbrowser plugin and the full JRE/JDK into /Library/Java/JavaVirtualMachines/
.
And additionally, software packages can come with their own JDK/JRE package. For instance, HP Peregrine Service Center does that.
So when each application comes with its own JDK/JRE, you need to tell in some configuration which one to use. In general, for all shell driven applications there is one environment variable you usually set for this and it's called JAVA_HOME. Software like tomcat respect this.
Take a closer look at this:
endor-2:~ garex$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.0_45, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
1.7.0_71, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
With the following java_home command you permanently switch over to Java 1.8 64 bit:
endor-2:~ garex$ java -fullversion
java full version "1.7.0_71-b14"
endor-2:~ garex$ /usr/libexec/java_home -v 1.8 -d64
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
endor-2:~ garex$ which java
/usr/bin/java
endor-2:~ garex$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
But remember: you could do that, but do not expect certain software to follow that. In my case I installed JRE and JDK.
By using the java_home command in your calling script you can always configure the right version for your application, e.g.
endor-2:~ garex$ /usr/libexec/java_home -v 1.8 -d64 -exec java -fullversion
java full version "1.8.0_45-b14"
endor-2:~ garex$ /usr/libexec/java_home -v 1.7.0 -d64 -exec java -fullversion
java full version "1.7.0_71-b14"
To permanently remove the 1.7.x, read https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html