Tuesday, May 26, 2015

Working with multiple Java versions

some of us, who are working on java 7 and java 8 projects are having trouble switching back and forth between the two java versions.

Adding the following lines to your .profile  file will solve that
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
alias jdk='$JAVA_HOME/bin/java -version'
alias jdk6="export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home;jdk"
alias jdk7="export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home;jdk"
alias jdk8="export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home;jdk"
(make sure your java is in for example /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk ,  you might have a different minor version,
also this example shows a mac configuration)


jdk - will show the current java version you are using
jdk8 - will change your JAVA_HOME to java 8
jdk7 - etc..

No comments:

Post a Comment