以切换jdk6和jdk7为例,脚本代码如下:
#!/bin/sh
#usage: . swith_jdk.sh [argvs]
jdk6_home=/usr/lib/jvm/jdk1.6.0_43
jdk7_home=/usr/lib/jvm/java-7-openjdk-amd64
case $1 in
j6)
export JAVA_HOME=$jdk6_home
;;
j7)
export JAVA_HOME=$jdk7_home
;;
*)
export JAVA_HOME=$jdk7_home
;;
esac
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib