I have three different JDKs on my system so I can appropriately switch between projects. Importing the appropriate JDK in my IDE is no issue, but the command line is. See, despite the fact that JAVA_HOME
for both my user as well as the system point to jre1.8.0_261
:
java --version
seems to still think that my default is Amazon's Corretto JDK, which I only need for one specific project:
C:\Users\jasonfil>java --version
openjdk 11.0.8 2020-07-14 LTS
OpenJDK Runtime Environment Corretto-11.0.8.10.1 (build 11.0.8+10-LTS)
This is also true for Powershell. I have also tried in both cmd
and Powershell as administrator. Same issue.
Curiously, when I query the environment variable from cmd
, I get the intended JDK:
C:\Users\jasonfil>echo %JAVA_HOME%
C:\Program Files (x86)\Java\jre1.8.0_261
While on Powershell, echo
just outputs the string %JAVA_HOME
literally:
PS C:\Users\jasonfil> echo %JAVA_HOME%
%JAVA_HOME%
My goal is to be able to switch between Java versions at will, like the update-alternatives
mechanism does in UNIX-based systems. Any ideas?