Ubuntu 安装和卸载 JDK 7 / JDK8 的两种方式以及双jdk的互相切换

这两天被一个JDK搞死了,编译mtk 8765平台出现如下的错误。各种猜测,最好找到是JDK版本低的原因。
avadoc: error - In doclet class com.google.doclava.Doclava, method start has thrown an exception java.lang.reflect.InvocationTargetException
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.android.okhttp.ConnectionPool not found
1 error

一、安装与更新 java jdk1.8
1、卸载安装的内容 jdk1.8
liansj dpkglist|grepijdkiiopenjdk8jdk:amd648u171b112 14.04amd64OpenJDKDevelopmentKit(JDK)iiopenjdk8jdkheadless:amd648u171b112 14.04amd64OpenJDKDevelopmentKit(JDK)(headless)iiopenjdk8jre:amd648u171b112 14.04amd64OpenJDKJavaruntime,usingHotspotJITliansj d p k g – l i s t | g r e p − i j d k i i o p e n j d k − 8 − j d k : a m d 64 8 u 171 − b 11 − 2   14.04 a m d 64 O p e n J D K D e v e l o p m e n t K i t ( J D K ) i i o p e n j d k − 8 − j d k − h e a d l e s s : a m d 64 8 u 171 − b 11 − 2   14.04 a m d 64 O p e n J D K D e v e l o p m e n t K i t ( J D K ) ( h e a d l e s s ) i i o p e n j d k − 8 − j r e : a m d 64 8 u 171 − b 11 − 2   14.04 a m d 64 O p e n J D K J a v a r u n t i m e , u s i n g H o t s p o t J I T l i a n s j sudo apt-get remove openjdk-8-jdk:amd64

2、安装open jdk-1.8 添加软件源
sudo add-apt-repository ppa:webupd8team/java
更新软件源
sudo apt-get update
安装 jdk1.8
sudo apt-get install openjdk-8-jdk

一共三个服务器,有两个正常安装了openjdk-8-jdk
但有一台服务器无法下载openjdk-8-jdk 而是下载了普通的jdk:
经过请教高人:手工修改atp的源list即可。
手工修改/etc/apt/sources.list,在最后添加如下几行
14.04
deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu trusty main
deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu trusty main

然后继续可以安装openjdk-8-jdk

二、 删除软链接

切换路径到/etc/alternatives

查看软连接ls -l java*

lrwxrwxrwx1 root root 46 6月 3 17:41 java ->/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java*
lrwxrwxrwx1 root root 56 6月 3 17:41 java.1.gz ->/usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
lrwxrwxrwx1 root root 43 6月 3 17:41 javac -> /usr/lib/jvm/java-7-openjdk-amd64/bin/javac*
lrwxrwxrwx1 root root 53 6月 3 17:41 javac.1.gz ->/usr/lib/jvm/java-7-openjdk-amd64/man/man1/javac.1.gz
lrwxrwxrwx1 root root 45 6月 3 17:41 javadoc ->/usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc*
lrwxrwxrwx1 root root 55 6月 3 17:41 javadoc.1.gz ->/usr/lib/jvm/java-7-openjdk-amd64/man/man1/javadoc.1.gz
lrwxrwxrwx1 root root 43 6月 3 17:41 javah ->/usr/lib/jvm/java-7-openjdk-amd64/bin/javah*
lrwxrwxrwx1 root root 53 6月 3 17:41 javah.1.gz -> /usr/lib/jvm/java-7-openjdk-amd64/man/man1/javah.1.gz
lrwxrwxrwx1 root root 43 6月 3 17:41 javap ->/usr/lib/jvm/java-7-openjdk-amd64/bin/javap*
lrwxrwxrwx 1 root root 53 6月 3 17:41 javap.1.gz ->/usr/lib/jvm/java-7-openjdk-amd64/man/man1/javap.1.gz

参照此例删除所用的软链接:

sudo update-alternatives –remove java/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
sudo update-alternatives –remove java/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

设置系统默认jdk 版本
sudo update-alternatives –install /usr/bin/java java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081
sudo update-alternatives –install /usr/bin/javac javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081
sudo update-alternatives –install /usr/bin/javap javap /usr/lib/jvm/java-8-openjdk-amd64/bin/javap 1081
sudo update-alternatives –install /usr/bin/javah javah /usr/lib/jvm/java-8-openjdk-amd64/bin/javah 1081
sudo update-alternatives –install /usr/bin/jar jar /usr/lib/jvm/java-8-openjdk-amd64/bin/jar 1081
sudo update-alternatives –install /usr/bin/javadoc javadoc /usr/lib/jvm/java-8-openjdk-amd64/bin/javadoc 1081
sudo update-alternatives –install /usr/bin/jarsigner jarsigner /usr/lib/jvm/java-8-openjdk-amd64/bin/jarsigner 1081

三、配置jdk 1.7 与1.8
sudo update-alternatives –config java
sudo update-alternatives –config javac
sudo update-alternatives –config javah
sudo update-alternatives –config javap
sudo update-alternatives –config jar
sudo update-alternatives –config javadoc
sudo update-alternatives –config jarsigner

sudo update-alternatives –auto java
sudo update-alternatives –auto javac
sudo update-alternatives –auto javap
sudo update-alternatives –auto javah
sudo update-alternatives –auto jconsole
sudo update-alternatives –auto jshell

查看列表:
$ sudo update-java-alternatives –list
[sudo] password for miaozhihua:
no talloc stackframe at ../source3/param/loadparm.c:4864, leaking memory
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64

jdk7 切换到jdk8
sudo update-java-alternatives -s java-8-openjdk-amd64

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值