实例场景应用(sun JDK1.7和sun JDK1.8切换alternatives)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实例场景应用(sun JDK1.7和sun JDK1.8切换alternatives)相关的知识,希望对你有一定的参考价值。

Java运用于执行java程序(java运行环境)
Javac运用于java程序编译(java程序开发环境)
步骤二:alternatives安装JDK
#alternatives --install /usr/bin/java java /usr/local/jdk版本/bin/java 1
#alternatives --install /usr/bin/javac java /usr/local/jdk版本/bin/javac 2
步骤二:查看可用的版本信息
#alternatives --display java
#alternatives --display javac
步骤三:切换java版本
#alternatives --config java
#alternatives --config javac
删除jdk版本(可选项,需要删除时使用--remove)
#alternatives --remove java /usr/local/java/jdk版本/bin
#alternatives --remove javac /usr/local/java/jdk版本/bin
步骤四:修改当前用户的jdk运行环境
#echo export JAVA_HOME=/usr/bin/java >>~/.bash_profile

echo export PATH=$PATH:$JAVA_HOME/bin >>~/.bash_profile

    # source ~/.bash_profile

注意需要注释掉/etc/profile文件里面的JAVA_HOM
查看及管理JAVA_HOME

echo $JAVA_HOME

/usr/local/jdk

java -version

java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

#实例

[cqs@centos7 jdk]$echo ’export JAVA_HOME=/usr/bin/java’ >>~/.bash_profile
[cqs@centos7 jdk]$ echo ‘export PATH=$PATH:$JAVA_HOME/bin’ >>~/.bash_profile
[cqs@centos7 jdk]$ source ~/.bash_profile

注意需要注释掉/etc/profile文件里面的JAVA_HOM

[cqs@centos7 jdk]$ echo $JAVA_HOME

/usr/bin/java

[cqs@centos7 jdk]$ echo $PATH

/usr/local/bin:/usr/bin:/usr/local/mysql/bin:/usr/local/sbin:/usr/sbin:/home/cqs/.local/bin:/home/cqs/bin:/usr/bin/java/bin

步骤一:alternatives安装JDK1.7(链接路径【link】:/usr/bin/java  链接名【name】:java 应用程序JAVA实际路径【path】:/home/cqs/data/jdk/jdk1.7.0_80/bin/java  优先级【priority】 :1)
    [cqs@centos7 jdk]$ sudo alternatives --install /usr/bin/java java ~/data/jdk/jdk1.7.0_80/bin/java 1
    [cqs@centos7 jdk]$ sudo alternatives --config java

There is 1 program that provides ‘java‘.
Selection Command

*+ 1 /home/cqs/data/jdk/jdk1.7.0_80/bin/java
Enter to keep the current selection[+], or type selection number:

[cqs@centos7 jdk]$ java -version

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

alternatives安装JDK1.8

[cqs@centos7 jdk]$ sudo alternatives --install /usr/bin/java java ~/data/jdk/jdk1.8.0_161/bin/java 2
[cqs@centos7 jdk]$ sudo alternatives --config java

There are 2 programs which provide ‘java‘.
Selection Command

  • 1 /home/cqs/data/jdk/jdk1.7.0_80/bin/java

    • 2 /home/cqs/data/jdk/jdk1.8.0_161/bin/java
      Enter to keep the current selection[+], or type selection number: 2

    [cqs@centos7 jdk]$ java -version

    java version "1.8.0_161"
    Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
    [cqs@centos7 jdk]$ sudo alternatives --config java
    There are 2 programs which provide ‘java‘.
    Selection Command

    1 /home/cqs/data/jdk/jdk1.7.0_80/bin/java
    *+ 2 /home/cqs/data/jdk/jdk1.8.0_161/bin/java
    Enter to keep the current selection[+], or type selection number: 1

    [cqs@centos7 jdk]$ java -version

    java version "1.7.0_80"
    Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

以上是关于实例场景应用(sun JDK1.7和sun JDK1.8切换alternatives)的主要内容,如果未能解决你的问题,请参考以下文章

1.走进java(本次阅读基于jdk1.7)

java的sun.misc.Unsafe类

运行SQL Developer时候出现java.lang.NoClassDefFoundError:com.sun.jdi.Bootstrap

package com.sun.crypto.provider does not exist问题解决

异常处理com.sun.image.codec.jpeg.JPEGImageEncoder

java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver