Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

batch file to switch between java version

@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 FilesJavajdk8u282-b08
    GOTO activate

:: java 11
:J11
    set JAVA_HOME=C:Program FilesJavajdk-11.0.10+9
    GOTO activate

:: latest java version
:latest
    set JAVA_HOME=C:Program FilesJavajdk-15.0.2+7
    GOTO activate

:: activates the selected java version
:activate
    set Path=%JAVA_HOME%in;%Path%
    echo Java %1 activated.
    GOTO exit

:: prints java version
:exit
    echo.
    echo Current Java version:
    java -version
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #batch #file #switch #java #version
ADD COMMENT
Topic
Name
9+6 =