Java version confusion need to set JAVA_HOME to Java11 - java

I'm not able to set Java11 to my JAVA_HOME env
I installed Java through home brew, how can I switch the version?
I needed to intall this java zulu to run Salesforce Data loader.
$ java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Homebrew (build 11.0.12+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.12+0, mixed mode)
$ /usr/libexec/java_home -V
/usr/libexec/java_home -V
Matching Java Virtual Machines (1):
16.0.2 (x86_64) "Azul Systems, Inc." - "Zulu 16.32.15" /Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home
ls -la /usr/bin/java
-rwxr-xr-x 1 root wheel 138880 Jan 1 2020 /usr/bin/java
ls -la /System/Library/Frameworks/JavaNativeFoundation.framework/Versions/Current
lrwxr-xr-x 1 root wheel 1 Jan 1 2020 /System/Library/Frameworks/JavaNativeFoundation.framework/Versions/Current -> A

Related

How can I determine whether the installed Java supports modules or not?

If I have a launcher script, how do I determine whether the JVM supports modules or not (e.g. 9+) to decide whether to launch with -classpath or --module script?
Approaches
There are several ways the information can be found. It's possible to parse the exact Java version or look for differences that are only found in a modular JVM or in non-modular JVMs.
Running java -version
Obviously it's possible to run the java command with a -version and parse the output:
% java -version
openjdk version "11.0.10" 2021-01-19 LTS
OpenJDK Runtime Environment Zulu11.45+27-CA (build 11.0.10+9-LTS)
OpenJDK 64-Bit Server VM Zulu11.45+27-CA (build 11.0.10+9-LTS, mixed mode)
However, this involves launching a process, running a number of setup/initialisation options, and validating/verifying other flags. This means that while quick, it won't be nearly instantaneous:
% time java -version
0.08s user 0.02s system 101% cpu 0.100 total
Running java -Xinternalversion
There is an internal option which isn't widely known about, but is documented in the -java -X flags, that doesn't instantiate the Java classes but simply returns the state of the binary:
-Xinternalversion
displays more detailed JVM version information than the
-version option
This launches slightly faster than the above:
% time java -Xinternalversion
OpenJDK 64-Bit Server VM (11.0.10+9-LTS) for bsd-amd64 JRE (Zulu11.45+27-CA) (11.0.10+9-LTS),
built on Dec 30 2020 12:39:54 by "zulu_re" with gcc 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)
0.01s user 0.01s system 88% cpu 0.029 total
This also works on OpenJ9 images:
% java -Xinternalversion
Eclipse OpenJ9 OpenJDK 64-bit Server VM (11.0.10+9) from linux-amd64 JRE
with Extensions for OpenJDK for Eclipse OpenJ9 11.0.10.0,
built on Jan 20 2021 08:58:22 by with g++-7.5 (GCC) 7.5.0
Reading JAVA_HOME/release file
If launching a process is considered too expensive, then reading or detecting files can be used instead. OpenJDK derived JVMs have a release file, which contains information about the Java version:
% grep VERSION $JAVA_HOME/release
IMPLEMENTOR_VERSION="Zulu11.45+27-CA"
JAVA_VERSION="11.0.10"
JAVA_VERSION_DATE="2021-01-19"
% grep VERSION $JAVA_8_HOME/release
JAVA_VERSION="1.8.0_282"
OS_VERSION="11.2"
Reading JAVA_HOME/lib/modules file
There are additional files that exist in a modular JVM (as part of the JEP 220 refactoring) which can be used to detect if the JVM supports modules or not. A modular JVM will have a $JAVA_HOME/lib/modules file with magic value 0xcafedada, which is understood by the file command as a module file:
% file $JAVA_HOME/lib/modules
/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/lib/modules: Java module image (little endian), version 1.0
The release file and the lib/modules exist in the OpenJDK and images produced by jlink. The release file exists on Java 8 and above, but the lib/modules only exists on Java 9 and above.
Some versions of Docker's OpenJDK image do not have the release file. Others install the Java version into a different location, which means that the JAVA_HOME (or equivalent) may not be found. If 100% guarantees are required that the same version of java is used in the path to launch the app as well as find the version, java -Xinternalversion is guaranteed to work and give the exact answer.
Looking for rt.jar/classes.zip
Another way of testing for the existence of a pre-modular JVM is to see whether rt.jar (or for really old JVMs, classes.zip) exists in JAVA_HOME/jre/lib. These files are missing in Java 9 and above.
Summary
If you already have JAVA_HOME, then the fastest way is to determine the existence of the JAVA_HOME/lib/modules file. For correctness, you could verify the magic number 0xcafedada (either little-endian or big-endian). However, this file doesn't exist on Java 8 or below but does on Java 9 and above, including jlink produced images.
Data
Collected data from various platforms:
openjdk docker images
(aka 'mystery meat' images) from https://hub.docker.com/_/openjdk/
for i in {7..15}
do
echo
echo openjdk:$i
docker run --rm -it openjdk:$i sh -c '
ls -l $(dirname $(readlink -f $(command -v java)))/../lib/modules
grep JAVA_VERSION= $(dirname $(readlink -f $(command -v java)))/../release
java -Xinternalversion'
done
openjdk:7
ls: cannot access /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/../lib/modules: No such file or directory
grep: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/../release: No such file or directory
OpenJDK 64-Bit Server VM (24.221-b02) for linux-amd64 JRE (1.7.0_221-b02), built on May 9 2019 19:23:05 by "pbuilder" with gcc 4.9.2
openjdk:8
ls: cannot access '/usr/local/openjdk-8/bin/../lib/modules': No such file or directory
JAVA_VERSION="1.8.0_282"
OpenJDK 64-Bit Server VM (25.282-b08) for linux-amd64 JRE (1.8.0_282-b08), built on Jan 11 2021 02:10:15 by "openjdk" with gcc 4.4.7 20120313 (Red Hat 4.4.7-23)
openjdk:9
-rw-r--r-- 1 root root 157113207 Apr 2 2018 /usr/lib/jvm/java-9-openjdk-amd64/bin/../lib/modules
grep: /usr/lib/jvm/java-9-openjdk-amd64/bin/../release: No such file or directory
OpenJDK 64-Bit Server VM (9.0.4+12-Debian-4) for linux-amd64 JRE (9.0.4+12-Debian-4), built on Apr 2 2018 07:28:15 by "buildd" with gcc 7.3.0
openjdk:10
-rw-r--r-- 1 root root 156084936 Oct 21 2018 /usr/lib/jvm/java-10-openjdk-amd64/bin/../lib/modules
grep: /usr/lib/jvm/java-10-openjdk-amd64/bin/../release: No such file or directory
OpenJDK 64-Bit Server VM (10.0.2+13-Debian-2) for linux-amd64 JRE (10.0.2+13-Debian-2), built on Oct 21 2018 10:11:46 by "buildd" with gcc 8.2.0
openjdk:11
-rw-rw-r-- 1 root root 142005674 Jan 12 10:31 /usr/local/openjdk-11/bin/../lib/modules
JAVA_VERSION="11.0.10"
OpenJDK 64-Bit Server VM (11.0.10+9) for linux-amd64 JRE (11.0.10+9), built on Jan 12 2021 05:23:33 by "openjdk" with gcc 4.4.7 20120313 (Red Hat 4.4.7-23)
openjdk:12
-rw-r--r-- 1 668 668 138934817 Jul 16 2019 /usr/java/openjdk-12/bin/../lib/modules
JAVA_VERSION="12.0.2"
OpenJDK 64-Bit Server VM (12.0.2+10) for linux-amd64 JRE (12.0.2+10), built on Jul 16 2019 00:57:08 by "mach5one" with gcc 7.3.0
openjdk:13
-rw-r--r-- 1 10668 10668 140052206 Dec 11 2019 /usr/java/openjdk-13/bin/../lib/modules
JAVA_VERSION="13.0.2"
OpenJDK 64-Bit Server VM (13.0.2+8) for linux-amd64 JRE (13.0.2+8), built on Dec 11 2019 09:23:26 by "mach5one" with gcc 8.2.0
openjdk:14
-rw-r--r-- 1 root root 143828463 Jul 8 2020 /usr/java/openjdk-14/bin/../lib/modules
JAVA_VERSION="14.0.2"
OpenJDK 64-Bit Server VM (14.0.2+12-46) for linux-amd64 JRE (14.0.2+12-46), built on Jul 8 2020 23:30:21 by "mach5one" with gcc 8.3.0
openjdk:15
-rw-r--r-- 1 root root 137265245 Dec 7 20:09 /usr/java/openjdk-15/bin/../lib/modules
JAVA_VERSION="15.0.2"
OpenJDK 64-Bit Server VM (15.0.2+7-27) for linux-amd64 JRE (15.0.2+7-27), built on Dec 7 2020 19:54:59 by "mach5one" with gcc 9.2.0
AdoptOpenJDK Hotspot images
From https://hub.docker.com/_/adoptopenjdk
for i in 8 {11..15}
do
echo
echo adoptopenjdk:$i-hotspot
docker run --rm -it adoptopenjdk:$i-hotspot sh -c '
ls -l $(dirname $(readlink -f $(command -v java)))/../lib/modules
grep JAVA_VERSION= $(dirname $(readlink -f $(command -v java)))/../release
java -Xinternalversion'
done
adoptopenjdk:8-hotspot
ls: cannot access '/opt/java/openjdk/bin/../lib/modules': No such file or directory
JAVA_VERSION="1.8.0_282"
OpenJDK 64-Bit Server VM (25.282-b08) for linux-amd64 JRE (1.8.0_282-b08), built on Jan 20 2021 11:56:52 by "jenkins" with gcc 7.5.0
adoptopenjdk:11-hotspot
-rw-r--r-- 1 root root 142006963 Jan 20 12:17 /opt/java/openjdk/bin/../lib/modules
JAVA_VERSION="11.0.10"
OpenJDK 64-Bit Server VM (11.0.10+9) for linux-amd64 JRE (11.0.10+9), built on Jan 20 2021 12:11:51 by "" with gcc 7.5.0
adoptopenjdk:12-hotspot
-rw-r--r-- 1 500 500 141885840 Jul 18 2019 /opt/java/openjdk/bin/../lib/modules
JAVA_VERSION="12.0.2"
OpenJDK 64-Bit Server VM (12.0.2+10) for linux-amd64 JRE (12.0.2+10), built on Jul 18 2019 14:41:47 by "jenkins" with gcc 7.3.1 20180303 (Red Hat 7.3.1-5)
adoptopenjdk:13-hotspot
-rw-r--r-- 1 root root 143013610 Jan 17 2020 /opt/java/openjdk/bin/../lib/modules
JAVA_VERSION="13.0.2"
OpenJDK 64-Bit Server VM (13.0.2+8) for linux-amd64 JRE (13.0.2+8), built on Jan 17 2020 15:30:29 by "jenkins" with gcc 7.3.1 20180303 (Red Hat 7.3.1-5)
adoptopenjdk:14-hotspot
-rw-r--r-- 1 root root 155307303 Jul 15 2020 /opt/java/openjdk/bin/../lib/modules
JAVA_VERSION="14.0.2"
OpenJDK 64-Bit Server VM (14.0.2+12) for linux-amd64 JRE (14.0.2+12), built on Jul 15 2020 09:06:52 by "" with gcc 7.5.0
adoptopenjdk:15-hotspot
-rw-r--r-- 1 root root 147653756 Jan 21 12:09 /opt/java/openjdk/bin/../lib/modules
JAVA_VERSION="15.0.2"
OpenJDK 64-Bit Server VM (15.0.2+7) for linux-amd64 JRE (15.0.2+7), built on Jan 21 2021 11:55:36 by "" with gcc 7.5.0
AdoptOpenJDK OpenJ9 images
From https://hub.docker.com/_/adoptopenjdk using the -openj9 flavours
for i in 8 {11..15}
do
echo
echo adoptopenjdk:$i-openj9
docker run --rm -it adoptopenjdk:$i-openj9 sh -c '
ls -l $(dirname $(readlink -f $(command -v java)))/../lib/modules
grep JAVA_VERSION= $(dirname $(readlink -f $(command -v java)))/../release
java -Xinternalversion'
done
adoptopenjdk:8-openj9
ls: cannot access '/opt/java/openjdk/bin/../lib/modules': No such file or directory
JAVA_VERSION="1.8.0_282"
Eclipse OpenJ9 OpenJDK 64-bit Server VM (1.8.0_282-b08) from linux-amd64 JRE with Extensions for OpenJDK for Eclipse OpenJ9 8.0.282.0, built on Jan 20 2021 08:35:35 by with g++-7.5 (GCC) 7.5.0
adoptopenjdk:11-openj9
-rw-r--r-- 1 root root 124147727 Jan 20 09:22 /opt/java/openjdk/bin/../lib/modules
JAVA_VERSION="11.0.10"
Eclipse OpenJ9 OpenJDK 64-bit Server VM (11.0.10+9) from linux-amd64 JRE with Extensions for OpenJDK for Eclipse OpenJ9 11.0.10.0, built on Jan 20 2021 08:58:22 by with g++-7.5 (GCC) 7.5.0
adoptopenjdk:12-openj9
-rw-r--r-- 1 500 500 125220100 Jul 19 2019 /opt/java/openjdk/bin/../lib/modules
JAVA_VERSION="12.0.2"
Eclipse OpenJ9 OpenJDK 64-bit Server VM (12.0.2+10) from linux-amd64 JRE with Extensions for OpenJDK for Eclipse OpenJ9 12.0.2.0, built on Jul 19 2019 19:53:58 by jenkins with g++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
adoptopenjdk:13-openj9
-rw-r--r-- 1 root root 124722695 Jan 17 2020 /opt/java/openjdk/bin/../lib/modules
JAVA_VERSION="13.0.2"
Eclipse OpenJ9 OpenJDK 64-bit Server VM (13.0.2+8) from linux-amd64 JRE with Extensions for OpenJDK for Eclipse OpenJ9 13.0.2.0, built on Jan 17 2020 10:38:21 by jenkins with g++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
adoptopenjdk:14-openj9
-rw-r--r-- 1 root root 128237302 Jul 15 2020 /opt/java/openjdk/bin/../lib/modules
JAVA_VERSION="14.0.2"
Eclipse OpenJ9 OpenJDK 64-bit Server VM (14.0.2+12) from linux-amd64 JRE with Extensions for OpenJDK for Eclipse OpenJ9 14.0.2.0, built on Jul 15 2020 14:33:14 by with g++-7.5 (GCC) 7.5.0
adoptopenjdk:15-openj9
-rw-r--r-- 1 root root 122382952 Jan 21 08:41 /opt/java/openjdk/bin/../lib/modules
JAVA_VERSION="15.0.2"
Eclipse OpenJ9 OpenJDK 64-bit Server VM (15.0.2+7) from linux-amd64 JRE with Extensions for OpenJDK for Eclipse OpenJ9 15.0.2.0, built on Jan 21 2021 08:12:28 by with g++-7.5 (GCC) 7.5.0
Azul Zulu images
From https://hub.docker.com/r/azul/zulu-openjdk
for i in 7 8 {11..15}
do
echo
echo azul/zulu-openjdk:$i
docker run --rm -it azul/zulu-openjdk:$i sh -c '
ls -l $(dirname $(readlink -f $(command -v java)))/../lib/modules
grep JAVA_VERSION= $(dirname $(readlink -f $(command -v java)))/../release
java -Xinternalversion'
done
azul/zulu-openjdk:7
ls: cannot access '/usr/lib/jvm/zulu7-ca-amd64/jre/bin/../lib/modules': No such file or directory
grep: /usr/lib/jvm/zulu7-ca-amd64/jre/bin/../release: No such file or directory
OpenJDK 64-Bit Server VM (24.292-b07) for linux-amd64 JRE (Zulu 7.44.0.11-CA-linux64) (1.7.0_292-b07), built on Dec 25 2020 02:30:15 by "zulu_re" with gcc 4.4.7 20120313 (Red Hat 4.4.7-3)
azul/zulu-openjdk:8
ls: cannot access '/usr/lib/jvm/zulu8-ca-amd64/jre/bin/../lib/modules': No such file or directory
grep: /usr/lib/jvm/zulu8-ca-amd64/jre/bin/../release: No such file or directory
OpenJDK 64-Bit Server VM (25.282-b08) for linux-amd64 JRE (Zulu 8.52.0.23-CA-linux64) (1.8.0_282-b08), built on Jan 12 2021 07:57:43 by "zulu_re" with gcc 4.4.7 20120313 (Red Hat 4.4.7-3)
azul/zulu-openjdk:11
-rw-r--r-- 1 root root 144713046 Jan 13 21:49 /usr/lib/jvm/zulu11-ca-amd64/bin/../lib/modules
JAVA_VERSION="11.0.10"
OpenJDK 64-Bit Server VM (11.0.10+9-LTS) for linux-amd64 JRE (Zulu11.45+27-CA) (11.0.10+9-LTS), built on Dec 30 2020 23:45:15 by "zulu_re" with gcc 4.9.2 20150212 (Red Hat 4.9.2-6)
azul/zulu-openjdk:12
-rw-r--r-- 1 root root 141878585 Jul 11 2019 /usr/lib/jvm/zulu-12-amd64/bin/../lib/modules
JAVA_VERSION="12.0.2"
OpenJDK 64-Bit Server VM (12.0.2+3) for linux-amd64 JRE (Zulu12.3+11-CA) (12.0.2+3), built on Jul 11 2019 18:01:29 by "zulu_re" with gcc 7.3.1 20180303 (Red Hat 7.3.1-5)
azul/zulu-openjdk:13
-rw-r--r-- 1 root root 143053558 Jan 13 21:37 /usr/lib/jvm/zulu13-ca-amd64/bin/../lib/modules
JAVA_VERSION="13.0.6"
OpenJDK 64-Bit Server VM (13.0.6+5-MTS) for linux-amd64 JRE (13.0.6+5-MTS) (Zulu13.37+21-CA), built on Dec 26 2020 00:17:26 by "zulu_re" with gcc 7.3.1 20180303 (Red Hat 7.3.1-5)
azul/zulu-openjdk:14
-rw-r--r-- 1 root root 146757927 Jul 10 2020 /usr/lib/jvm/zulu-14-amd64/bin/../lib/modules
JAVA_VERSION="14.0.2"
OpenJDK 64-Bit Server VM (14.0.2+12) for linux-amd64 JRE (14.0.2+12) (Zulu14.29+23-CA), built on Jul 10 2020 22:15:57 by "zulu_re" with gcc 7.3.1 20180303 (Red Hat 7.3.1-5)
azul/zulu-openjdk:15
-rw-r--r-- 1 root root 140186164 Jan 22 17:19 /usr/lib/jvm/zulu15-ca-amd64/bin/../lib/modules
JAVA_VERSION="15.0.2"
OpenJDK 64-Bit Server VM (15.0.2+7) for linux-amd64 JRE (15.0.2+7) (Zulu15.29+15-CA), built on Jan 21 2021 06:01:59 by "zulu_re" with gcc 7.3.1 20180303 (Red Hat 7.3.1-5)

Apache Ignite 2.5.0 Java 10 Compatibility on Mac

I have setup my JAVA_HOME environment variable by $HOME/.profile this way:
export JAVA_HOME="$(/usr/libexec/java_home)"
Downloaded the release apache-ignite-fabric-2.5.0-bin.zip
Checking environment:
josepens-mbp:bin josepen$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
josepens-mbp:bin josepen$ $JAVA_HOME/bin/java --version
java 10.0.1 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Everything seems fine, however when running bin/.ignite.sh get the following error:
josepens-mbp:bin josepen$ ./ignite.sh
./ignite.sh, ERROR:
The version of JAVA installed in JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home is incorrect.
Please point JAVA_HOME variable to installation of JDK 1.8 or JDK 9.
You can also download latest JDK at http://java.com/download
Is Ignite compatible with Java 10?
Ignite did not tested against JDK 10 and there might be unknown issues. It's recommended to use JDK 1.8 or 9.
But if you want, you may hack scripts and run on 10. For example in bin/include/functions.sh line 66 add java 10: "$JAVA" -version 2>&1 | grep -qE 'version "(1.8.*|9.*|10.*)"' and bin/ignite.sh line 154: ${JAVA_HOME}/bin/java -version 2>&1 | grep -qE 'java version "(9.*|10.*)"'.

How to get Java 6 JDK on mavericks

I am trying to get the Java 6 JDK on my mac. I've tried downloading this http://support.apple.com/kb/DL1572
But I can't find it in /Library/Java/JavaVirtualMachines
I already have Java 8 installed, and I don't want to remove it or replace it, I just want to have the Java 1.6 JDK that I can work with on my computer. (Need it to do my mandatory assignemtns for class. Studying Computer Science)
What do I have to do? Thanks in advance!
It installs in a different location.
$ uname -a
Darwin Yoyo-2.local 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64 i386 MacBookPro11,3 Darwin
$ /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

How do I know if Java is added to the path in Mac?

I'm reading instructions on setting up a thing and it says,
Add the Java bin directory to the PATH variable
Now, I don't remember if I've added it to the path before or not but if I open Terminal and type java -version from the command line and press enter it shows:
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
Does this mean java is already in the path and I don't need to add it? Thanks for all your wonderful support. May your days be filled with flowers and pokemons.
To see how a command resolves to an executable on your $PATH, use the which command
$ which java
/usr/bin/java
… or the equivalent bash builtin, type -p:
$ type -p java
/usr/bin/java
On a Mac OS X system with Oracle Java installed, /usr/bin/java is a symbolic link.
$ ls -l /usr/bin/java
lrwxr-xr-x 1 root wheel 74 23 Oct 16:23 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

Mac OS X 10.6.7 Java Path Current JDK confusing

I have trouble understanding (actual paths vs links) for multiple java versions on my Mac OSX. Normally in windows if I have multiple versions installed in my machine, I can just take the path of which ever version I want and use it. But in MAC OS X I undertand that there is something called links that is being pointed to CurrentJDK, and if I want to use a different version I will need to change the link to CurrentJdk right? But what is confusing for me is that as you can see below all my versions are pointing to the same CurrentJDK which means all versions point to current version? I was expecting only one of them would be pointing to CurrentJDK and I could just change it to which ever one I need which is not the case here. All I need to know is how to find the bin(Commands) folder path for each version, so that I can just use it to point to CurrentJDK? Also tell me how to change the link to CurrentJDK.
$ java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
$ pwd
/System/Library/Frameworks/JavaVM.framework/Versions
$ ls -l
lrwxr-xr-x 1 root wheel 5 Mar 20 11:12 1.3 -> 1.3.1
drwxr-xr-x 3 root wheel 102 Dec 2 2009 1.3.1
lrwxr-xr-x 1 root wheel 10 Mar 20 11:12 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 20 11:12 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 20 11:12 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 20 11:12 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 20 11:12 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 20 11:12 1.6.0 -> CurrentJDK
drwxr-xr-x 10 root wheel 340 Mar 20 11:13 A
lrwxr-xr-x 1 root wheel 1 Mar 20 11:12 Current -> A
lrwxr-xr-x 1 root wheel 59 Mar 20 11:12 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
For different types of JDKs or installations, you will have different paths.
On Mac OS X Mavericks, the path I found as following:
1) Built-in JRE default:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
2) JDKs downloaded from Apple:
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
3) JDKs downloaded from Oracle:
/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
Most possibly you only have one jdk installed, thus all the soft links points to the same jdk. If you however did have multiple jdks installed you would need to choose which one to use with the 'Java Preferences' app in your /Application/Utilities.
Soft links are by the way created with the ln -s command from Terminal.
Just run following commands:
$ brew update
$ brew install jenv
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/
oracle64-1.8.0.45 added
1.8.0.45 added
1.8 added
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
oracle64-1.7.0.79 added
1.7.0.79 added
1.7 added
$ jenv versions
* system (set by /Users/wanluwang/.jenv/version)
1.7
1.7.0.79
1.8
1.8.0.45
oracle64-1.7.0.79
oracle64-1.8.0.45
$ 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)
$ jenv global oracle64-1.7.0.79
$ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
From Apple Technical Q&A Java Questions:
User Preferences
On Mac OS X, the Java runtime provides the java.util.prefs API which is backed by the standard Mac OS X Preferences API and directories. Simply using this pure Java API reads and stores your application's preferences in ~/Library/Preferences in a Mac OS X property list file. For applications that may already have their own preferences format, these preferences should be stored in the ~/Library/Preferences directory as well. This directory can be reached from Java code by creating a file with the path of System.getProperty("user.home") + "/Library/Preferences/" + "com.example.your.Application". An application that should have global preferences across all users could instead reside in /Library/Preferences, however this directory is not writable by non-admin users.
set $JAVA_HOME=$(/usr/libexec/java_home)
in your .bash_profile
or export JAVA_HOME=$(/usr/libexec/java_home);
echo $JAVA_HOME

Categories