Skip to content

Instantly share code, notes, and snippets.

@sryze
Created March 19, 2022 16:50
Show Gist options
  • Save sryze/8148f04366557abbc1efde5bb6ff842b to your computer and use it in GitHub Desktop.
Save sryze/8148f04366557abbc1efde5bb6ff842b to your computer and use it in GitHub Desktop.
Script for switching between different versions of Java on Windows (needs Git Bash or similar shell)
#!/bin/sh
java_version=$1
java_home=
IFS=$'\n'
for d in $(find "/c/Program Files/Java" -name "jdk*$java_version*" -type d); do
java_home="$d"
done
if [ -z "$java_home" ]; then
echo "Could not find Java version $java_version"
else
export JAVA_HOME="$java_home"
export PATH="$java_home/bin:$PATH"
echo "Activated Java version $java_version ($java_home)"
fi
@sryze
Copy link
Author

sryze commented Mar 19, 2022

Usage:

source set-java-version.sh 11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment