I installed java jdk 20 and jdk 17 through SDKMAN.
I want to be able to do something like this.
alias java17="export JAVA_HOME=`/usr/libexec/java_home -v 17`; java -version"
But when i do this
/usr/libexec/java_home -V
It gives me output like this
Matching Java Virtual Machines (3): 11.0.19 (x86_64) "OpenLogic-OpenJDK" - "OpenLogic-OpenJDK 11" /Library/Java/JavaVirtualMachines/openlogic-openjdk-11.jdk/Contents/Home 1.8.381.09 (arm64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home 1.8.0_202 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home /Library/Java/JavaVirtualMachines/openlogic-openjdk-11.jdk/Contents/Home
Both Jdk20 and jdk17 are undetected by java_home
path of my jdk20 and jdk17 are -
/Users/default/.sdkman/candidates/java/20.0.2-oracle
/Users/default/.sdkman/candidates/java/17.0.8-oracle
I want java_home to detect jdk17 and jdk20 while I do this
/usr/libexec/java_home -V
I am unable to make java_home detect jdk17 and jdk20. I looked up on internet but didn't find any solution.
Though I found one work around method in which we imitate the folder structure of JDKs installed without SDKMAN.
This is how jdks installed without sdkman looks likee
Contents/
Info.plist
Home/
<actual JDK files here>
But when installed through sdkman, it is like this
jdk_root-folder/
<actual jdk files>
In the work around method we need to imitate that file structure with Contents, Info.plist, Home, and then linking original jdk there.
But the method is little complicated and we have to repeat it for every single version.
It would be great if there is any easier way.
Thank you.
The java_home
script doesn't know about SDKman! Luckily, there is a built in home
(or h
) command like
sdk home java 17.0.2.fx-librca
outputs
/Users/efrisch/.sdkman/candidates/java/17.0.2.fx-librca
If you want the currently selected one, that's
$HOME/.sdkman/candidates/java/current