batch file to switch between java version

Solutions on MaxInterview for batch file to switch between java version by the best coders in the world

showing results for - "batch file to switch between java version"
Michel
20 Feb 2019
1@echo off
2echo.
3
4IF "%1" == ""       GOTO NoParams
5IF "%1" == "8"      GOTO J8
6IF "%1" == "11"     GOTO J11
7IF "%1" == "latest" GOTO latest
8
9IF "%1" == "-h"         GOTO help
10IF "%1" == "--help"     GOTO help
11
12:NoParams
13    echo Enter Java version
14    GOTO options
15    
16:help
17    echo Usage: javaVer [java version]
18    GOTO options
19
20:: available java versions
21:options
22    echo options: 8, 11, latest.
23    GOTO exit
24
25:: java 8
26:J8
27    set JAVA_HOME=C:\Program Files\Java\jdk8u282-b08
28    GOTO activate
29
30:: java 11
31:J11
32    set JAVA_HOME=C:\Program Files\Java\jdk-11.0.10+9
33    GOTO activate
34
35:: latest java version
36:latest
37    set JAVA_HOME=C:\Program Files\Java\jdk-15.0.2+7
38    GOTO activate
39
40:: activates the selected java version
41:activate
42    set Path=%JAVA_HOME%\bin;%Path%
43    echo Java %1 activated.
44    GOTO exit
45
46:: prints java version
47:exit
48    echo.
49    echo Current Java version:
50    java -version
51
similar questions
queries leading to this page
batch file to switch between java version