Is there a way to change JDK version easily in cmd? like the version on mac. Change Default JDK on Mac.
Found a single batch file to be a simpler solution. Adding batch file location path to system environmental variables will allow you to execute it from cmd.
Batch file (javaVer.bat):
@echo off
echo.
IF "%1" == ""       GOTO NoParams
IF "%1" == "8"      GOTO J8
IF "%1" == "11"     GOTO J11
IF "%1" == "latest" GOTO latest
IF "%1" == "-h"         GOTO help
IF "%1" == "--help"     GOTO help
:NoParams
    echo Enter Java version
    GOTO options
    
:help
    echo Usage: javaVer [java version]
    GOTO options
:: available java versions
:options
    echo options: 8, 11, latest.
    GOTO exit
:: java 8
:J8
    set JAVA_HOME=C:\Program Files\Java\jdk8u282-b08
    GOTO activate
:: java 11
:J11
    set JAVA_HOME=C:\Program Files\Java\jdk-11.0.10+9
    GOTO activate
:: latest java version
:latest
    set JAVA_HOME=C:\Program Files\Java\jdk-15.0.2+7
    GOTO activate
:: activates the selected java version
:activate
    set Path=%JAVA_HOME%\bin;%Path%
    echo Java %1 activated.
    GOTO exit
:: prints java version
:exit
    echo.
    echo Current Java version:
    java -version
Usage: javaVer [java version]
exp: javaVer 8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With