0

As far as i know you can use every Java version when you are just in the right directory. Lets say i have on my PC Java 8 and Java 15. They are both located in C:\Program Files\java.
So when i go in C:\Program Files\java\jre1.8.0_291\bin and run in cmd java.exe -version i get the version 1.8 .
The same goes with Powershell.

But here comes the problem. When i go to C:\Program Files\java\jdk-15.0.1\bin i get in cmd the version 1.15, but in Powershell i still get 1.8.
I think that Powershell always refers to the standard JRE installed.

1
  • 1
    What does Get-Command java.exe resolve to (when you're inside the jdk-15* bin folder)? Commented May 12, 2021 at 15:46

2 Answers 2

2

You need to add .\ before the command.

java.exe will run the first java in your PATH.
.\java.exe will run the java.exe in your current directory.

Sign up to request clarification or add additional context in comments.

1 Comment

Thaks for the Answer. Didnt know that PS is so close to the Linux terminal.
1

you need .\ before the command to run the one in your current directory

personally, I use the below to switch versions, its a script that sets the JAVA home. This can be used when in any java dirs to use different versions

@echo off
set JAVA_HOME=C:\Program Files\Java\jdk-16
set Path=%JAVA_HOME%\bin;%Path%
echo Java 16 activated.

link to method I used below https://www.happycoders.eu/java/how-to-switch-multiple-java-versions-windows/

1 Comment

Thanks for the script. I will use it in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.