Created
March 23, 2023 12:09
-
-
Save timguy/2f2033cc7a8a05f5fbe0e237dcb167ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: set Java versions (permanently with setx and not only for console with set) | |
@echo off | |
echo. | |
IF "%1" == "" GOTO NoParams | |
IF "%1" == "8" GOTO J8 | |
IF "%1" == "17" GOTO J17 | |
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, 17, latest. | |
GOTO exit | |
:: java 8 | |
:J8 | |
setx JAVA_HOME=C:\Program Files\AdoptOpenJDK\jre-8.0.282.8-hotspot | |
GOTO activate | |
:: java 17 | |
:J17 | |
setx JAVA_HOME=C:\P\Java\AdoptOpenJdk_temurin-17.0.6 | |
GOTO activate | |
:: latest java version | |
:latest | |
setx JAVA_HOME=C:\Program Files\Java\j21 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment