macでjava7とjava8を使う

参考はこちらです。 http://qiita.com/skohara/items/d43d10aa41f9c0f96fa5

java8でjava8が使える様になってjava7でjava7が使える様になります。

~/.zshrcに [shell] java7() { setjdk 1.7; java $@ }

java8() { setjdk 1.8; java $@ } function setjdk() { if [ $# -ne 0 ]; then removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin' if [ -n "${JAVA_HOME+x}" ]; then removeFromPath $JAVA_HOME fi export JAVA_HOME=/usr/libexec/java_home -v $@ export PATH=$JAVA_HOME/bin:$PATH fi } function removeFromPath() { export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;") } setjdk 1.8

[/shell]

source ~/.zshrcして [shell gutter="false"] [astel@MacBook-Pro ] $ java -version java version "1.8.0_05" Java(TM) SE Runtime Environment (build 1.8.0_05-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) [astel@MacBook-Pro ] $ [astel@MacBook-Pro ] $ [astel@MacBook-Pro ] $ java7 -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) [astel@MacBook-Pro ] $ 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) [astel@MacBook-Pro ] $ [astel@MacBook-Pro ] $ [astel@MacBook-Pro ] $ [astel@MacBook-Pro ] $ java8 -version java version "1.8.0_05" Java(TM) SE Runtime Environment (build 1.8.0_05-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) [astel@MacBook-Pro ] $ [astel@MacBook-Pro ] $ [astel@MacBook-Pro ] $ java -version java version "1.8.0_05" Java(TM) SE Runtime Environment (build 1.8.0_05-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) [astel@MacBook-Pro ] $
[/shell]

すばらしい

あとエイリアス消すコマンドもはじめてみました。 [astel@MacBook-Pro ] $ unalias java8