首页 > 代码库 > 〖Linux〗多个JDK版本之间快速切换
〖Linux〗多个JDK版本之间快速切换
由于工作的需要,经常要切换JDK版本比如我HOME目录下有三个JDK版本:
~/apt/jdk1.6.0_34 # JDK6~/apt/jdk1.7.0_67 # JDK7~/apt/jdk1.8.0_05 # JDK8
比如编译Android整套系统源代码,Google建议使用JDK6
在实现的工作中,由于项目的实际需求,要使用JDK7来执行一些工具
为了方便切换JDK版本,我写了一个脚本:
1 #!/bin/sh 2 # usage: . this_file [argvs] 3 4 jdk6_home=~/apt/jdk1.6.0_34 5 jdk7_home=~/apt/jdk1.7.0_67 6 jdk8_home=~/apt/jdk1.8.0_05 7 8 # 默认JDK6 9 case $1 in10 jdk6 )11 export JAVA_HOME=$jdk6_home12 ;;13 jdk7 )14 export JAVA_HOME=$jdk7_home15 ;;16 jdk8 )17 export JAVA_HOME=$jdk8_home18 ;;19 * )20 export JAVA_HOME=$jdk6_home21 ;;22 esac23 24 export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH25 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
使用方法:
例如:在需要切换的JDK7的时候,在Shell中执行 . [脚本文件名] jdk7
前提:把JDK7下载并解压到 ~/apt/jdk1.7.0_67(根据自身需求修改)
JDK版本下载链接:
Java SE 1.1:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase11-419415.html
Java SE 1.2:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase12-419414.html
Java SE 1.3:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase13-419413.html
Java SE 1.4:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase14-419411.html
JDK5下载:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase5-419410.html
JDK6下载:http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html
JDK7下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
JDK8下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html