change_jdk
一.change_jdk
if [ x$1 == x ]; then echo default jdk1.7 exit 0 fi if [ x$1 == x1.6 ]; then echo change jdk to 1.6 export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_37 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH java -version fi if [ x$1 == x1.7 ]; then echo change jdk to 1.7 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH java -version fi if [ x$1 == x1.8 ]; then echo change jdk to 1.8 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH java -version fi
二.运行
gatsby@ubuntu:~/workspace$ source change_jdk 1.8 change jdk to 1.8 openjdk version "1.8.0_275" OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~16.04-b01) OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode) gatsby@ubuntu:~/workspace$ java -version openjdk version "1.8.0_275" OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~16.04-b01) OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode) gatsby@ubuntu:~/workspace$