Platform: RK3399
OS: Android 7.1
Kernel: v4.4.83
当前版本:
build@build-server:$ javac -version$
javac 1.6.0_45
build@build-server:
build@build-server:$ java -version14.04-b11)
openjdk version “1.8.0_171”
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-2
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
原理:
本质上版本不一致是使用的可执行文件不一致,只要切换和重新链接对应的可执行文件即可.
包括使用update-alternatives的命令也是这个原理.
Javac版本修改:
下面是修改javac的过程
查看命令路径
root@build-server:/home/build# which java javac
/usr/bin/java
/usr/bin/javac
查看链接
root@build-server:/home/build# ls -l /usr/bin/java*
lrwxrwxrwx 1 root root 22 May 12 2016 /usr/bin/java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 23 Apr 6 2017 /usr/bin/javac -> /etc/alternatives/javac
root@build-server:/home/build# ls -l /etc/alternatives/java*
lrwxrwxrwx 1 root root 46 Apr 18 11:09 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
lrwxrwxrwx 1 root root 43 Apr 6 2017 /etc/alternatives/javac -> /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
重新建立链接
root@build-server:/home/build# rm /etc/alternatives/javac
root@build-server:/home/build# ln -s /usr/lib/jvm/java-8-openjdk-amd64/bin/javac /etc/alternatives/javac
root@build-server:/home/build# ls -l /etc/alternatives/java*
lrwxrwxrwx 1 root root 46 Apr 18 11:09 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
lrwxrwxrwx 1 root root 43 Apr 18 11:34 /etc/alternatives/javac -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javac
查看版本
root@build-server:/home/build# javac -version
javac 1.8.0_171
root@build-server:/home/build# java -version
openjdk version “1.8.0_171”
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-2~14.04-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
Javac版本修改:
一开始我的javac版本也是有问题,一直是1.6版本,但是我已经使用命令update-alternatives切换到了1.8版本,但是javac是1.6.
后来发现是之前在做其他项目的时候在.bashrc中写死了,注释掉了就好.
build@build-server:~$ cat .bashrc
#Kris
#export JAVA_HOME=/home/build/tools/jdk1.6.0_45
#export JRE_HOME=$JAVA_HOME/jre
#export PATH=JAVA_HOME/bin:JRE_HOME/bin:$PATH
原作者:KrisFei
更多回帖