Since I wind up testing things on multiple JDKs frequently, I thought I'd
share a handy tool for quickly swapping both JAVA_HOME, and its values from
$PATH:

http://timboudreau.com/files/fixpath

You just set up shell aliases source the output of it.  Usage:

0.  Have nodejs on your path (depending on your Linux distro, you may need
to change the shebang at the top to reference "nodejs" instead of "node" -
Debian based distros use "nodejs")

1. Copy this script to some place like ~/bin/fixpath (you'll use that in
the shell aliases0

2. Set up some environment variables for different JDKs in your .bashrc:

export JDK_7=/opt/jdk7
export JDK_8=/opt/jdk8
export JDK_9=/opt/oracle-jdk-bin-9.0.4
export JDK_10=/opt/jdk10
export JDK_14=/opt/jdk14

3. Set up some aliases in your .bashrc too:
# Fast switch java versions for the current shell
alias jdk7='. <(~/bin/fixpath JDK_*/bin JDK_7/bin JAVA_HOME)'
alias jdk8='. <(~/bin/fixpath JDK_*/bin JDK_8/bin JAVA_HOME)'
alias jdk9='. <(~/bin/fixpath JDK_*/bin JDK_9/bin JAVA_HOME)'
alias jdk14='. <(~/bin/fixpath JDK_*/bin JDK_14/bin JAVA_HOME)'
alias jdkGraal='. <(~/bin/fixpath JDK_*/bin JDK_GRAAL/bin JAVA_HOME)'

4. Open a new shell, or `. ~/.bashrc` and you're good to go.  Just run the
command jdk14 and you're using JDK 14, etc.

Thought I'd share,

Tim

-- 
http://timboudreau.com

Reply via email to