Skip to content

Instantly share code, notes, and snippets.

@yarmand
Created December 2, 2014 11:54
Show Gist options
  • Save yarmand/c3e99bf78c22012714c4 to your computer and use it in GitHub Desktop.
Save yarmand/c3e99bf78c22012714c4 to your computer and use it in GitHub Desktop.
chjava for OSX
JAVA_HOME_CMD=/usr/libexec/java_home
function chjava(){
if [ $# -eq 0 ] ; then
$JAVA_HOME_CMD -V
return
fi
export JAVA_HOME=`$JAVA_HOME_CMD -v $*`
}
@yarmand
Copy link
Author

yarmand commented Dec 2, 2014

example usage:

~ » java -version                                                                                                                      
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

~ » chjava                                                                                                                             
Matching Java Virtual Machines (4):
    1.8.0_25, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
    1.7.0_71, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
    1.6.0_65-b14-466.1, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-466.1, i386:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

~ » chjava 1.7                                                                                                                         

~ » java -version                                                                                                                      
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

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