A quick way to change between java versions in windows cmd
Put jvs.exe in a folder, and add that folder to your system PATH environnement variable. Make sure jvs.exe is in a folder where it has read/write permissions.
{
"17": "C:/Program Files/Zulu/zulu-17",
"8": "C:/Program Files/Zulu/zulu-8",
"install": {
"zulu17": "https://cdn.azul.com/zulu/bin/zulu17.44.53-ca-jdk17.0.8.1-win_x64.zip",
"zulu20": "https://cdn.azul.com/zulu/bin/zulu20.32.11-ca-jdk20.0.2-win_x64.zip",
"zulu8": "https://cdn.azul.com/zulu/bin/zulu8.72.0.17-ca-jdk8.0.382-win_x64.zip"
}
}
The config jvs.json
needs to be in the same folder as jvs.exe
.
In this example config, the command jvs 17
will delete existing java dirs in the PATH
env variable, and add the directory C:/Program Files/Zulu/zulu-17/bin
to PATH
.
It will also set JAVA_HOME
to C:/Program Files/Zulu/zulu-17
.
The command jvs install zulu17
will download the zip file at https://cdn.azul.com/zulu/bin/zulu17.44.53-ca-jdk17.0.8.1-win_x64.zip
and extract it to a folder zulu17
in the same place as jvs.exe
.
It will then add that folder to jvs.json
so that you can jvs zulu17
.
jvs <javaVersion>
jvs install <javaVersion>
This does not change the system wide PATH env variable, it calls _putenv in the parent process (so cmd.exe), so that only that process java path will be changed. It uses VirtualAllocEx, WriteProcessMemory and CreateRemoteThread in order to achieve that.
- nlohmann json: https://github.com/nlohmann/json (for the json config jvs.json)
- curl: https://github.com/curl/curl (to download jdk zip)
- miniz: https://github.com/richgel999/miniz (to extract downloaded jdk zip)
- indicators: https://github.com/p-ranav/indicators (for the progress bar)
Because c++ is fun, and it allows to have a cool json config file, as well as the ability to remove existing java paths to avoid conflicts. Overall it's fast, and it will allow more features in the future.