上次有說到 怎麼安裝 Java6與 Java7
http://esmondjhchang.blogspot.tw/2014/11/ubuntu-12-java67.html
因為我常常要在 JAVA6與JAVA7之間切換...
因此, 本篇只是分享一個個人的切換script
請先到 https://code.google.com/p/webupd8/downloads/detail?name=update-java-0.5b
下載一個 update-java-0.5b的script (這個直接使用就可以了, 不過需要在GUI環境)
因為我不知我的PC被我怎麼搞的, 所以上面的 update-java-0.5b 居然只能切換部份環境
所以...
使用時, 直接在GUI裡的 console 輸入 java_swap後,
若輸入 Y, 則系統會切換成JAVA6 (compile Android 4.4.4-)
若輸入 N, 則系統會切換成 JAVA7 (compile Android 5+)
接著會出現一個對話框, 再選擇 JAVA的位置即可
如: JAVA6 就選 java-6-oracle (小心選, 不然會只切一半)
java_swap 的 Script 如下 (小弟是把兩個檔, update-java-0.5b 與 此script 放到 /bin 裡)
記得要 chmod 成可執行狀態唷~
#!/bin/bash
JAVA6_PATH=/usr/lib/jvm/java-6-oracle
JAVA7_PATH=/usr/lib/jvm/java-7-openjdk-amd64
read -t 30 -n 3 -p "Set Environment to JAVA6? (Y for 6/N for 7) " ANS_YN
sudo /bin/update-java-0.5b
case $ANS_YN in
"NO"|"No"|"no"|"nO"|"N"|"n")
echo "Set to JAVA7 ..."
sudo update-alternatives --set java $JAVA7_PATH/jre/bin/java
sudo update-alternatives --set javac $JAVA7_PATH/bin/javac
sudo update-alternatives --set javadoc $JAVA7_PATH/bin/javadoc
sudo update-alternatives --set javah $JAVA7_PATH/bin/javah
sudo update-alternatives --set javap $JAVA7_PATH/bin/javap
sudo update-alternatives --set javaws $JAVA7_PATH/jre/bin/javaws
# sudo echo "export J2SDKDIR=/usr/lib/jvm/java-7-openjdk-amd64" > /etc/profile.d/jdk.sh
# sudo echo "export J2REDIR=/usr/lib/jvm/java-7-openjdk-amd64/jre" >> /etc/profile.d/jdk.sh
sudo echo "export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64">> /etc/profile.d/jdk.sh
# sudo echo "export PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/jvm/java-7-openjdk-amd64/bin:/usr/lib/jvm/java-7-openjdk-amd64/jre/bin:/usr/lib/jvm/java-6-oracle/db">> /etc/profile.d/jdk.sh
sudo echo "export DERBY_HOME=/usr/lib/jvm/java-6-oracle/db" >> /etc/profile.d/jdk.sh
echo "Set to JAVA7 completed... Please REBOOT manually..."
;;
*)
echo "Set to JAVA6..."
sudo update-alternatives --set java $JAVA6_PATH/jre/bin/java
sudo update-alternatives --set javac $JAVA6_PATH/bin/javac
sudo update-alternatives --set javadoc $JAVA6_PATH/bin/javadoc
sudo update-alternatives --set javah $JAVA6_PATH/bin/javah
sudo update-alternatives --set javap $JAVA6_PATH/bin/javap
sudo update-alternatives --set javaws $JAVA6_PATH/jre/bin/javaws
# sudo echo "export J2SDKDIR=/usr/lib/jvm/java-6-openjdk-amd64" > /etc/profile.d/jdk.sh
# sudo echo "export J2REDIR=/usr/lib/jvm/java-6-openjdk-amd64/jre" >> /etc/profile.d/jdk.sh
sudo echo "export JAVA_HOME=/usr/lib/jvm/java-6-oracle">> /etc/profile.d/jdk.sh
# sudo echo "export PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/jvm/java-6-openjdk-amd64/bin:/usr/lib/jvm/java-6-openjdk-amd64/jre/bin:/usr/lib/jvm/java-6-oracle/db">> /etc/profile.d/jdk.sh
# sudo echo "export DERBY_HOME=/usr/lib/jvm/java-6-oracle/db" >> /etc/profile.d/jdk.sh
echo "Set to JAVA6 completed... Please REBOOT manually..."
;;
esac
沒有留言:
張貼留言