〖Linux〗多個JDK版本之間快速切換

因爲工做的須要,常常要切換JDK版本好比我HOME目錄下有三個JDK版本:html

~/apt/jdk1.6.0_34 # JDK6
~/apt/jdk1.7.0_67 # JDK7
~/apt/jdk1.8.0_05 # JDK8

好比編譯Android整套系統源代碼,Google建議使用JDK6java

在實現的工做中,因爲項目的實際需求,要使用JDK7來執行一些工具git

 

爲了方便切換JDK版本,我寫了一個腳本:github

複製代碼

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 in
10     jdk6 )
11         export JAVA_HOME=$jdk6_home
12         ;;
13     jdk7 )
14         export JAVA_HOME=$jdk7_home
15         ;;
16     jdk8 )
17         export JAVA_HOME=$jdk8_home
18         ;;
19     * )
20         export JAVA_HOME=$jdk6_home
21         ;;
22 esac
23 
24 export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
25 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

複製代碼

使用方法:oracle

  例如:在須要切換的JDK7的時候,在Shell中執行  . [腳本文件名] jdk7 工具

  前提:把JDK7下載並解壓到 ~/apt/jdk1.7.0_67(根據自身需求修改)this

 

JDK版本下載連接:htm

  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.htmlget

------------ 
微博:http://weibo.com/scue 
Github:http://github.com/scueit

相關文章
相關標籤/搜索