CentOS7默认JDK是OpenJDK1.8.*,即使配置了JDK输入java -version也是如下信息:
[root@apm-master ~]# java -version openjdk version "1.8.0_161" OpenJDK Runtime Environment (build 1.8.0_161-b14) OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
乍一看是1.8.0_161
没错,可惜他是openjdk,而我们的应用通常都运行在Oracle JDK中,于是此时就需要使用alternatives
命令。
alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_161/bin/java 3 alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.8.0_161/bin/javac 3
然后执行下面的命令进行设置:
alternatives --config java
共有 3 个提供“java”的程序。 选项 命令 ----------------------------------------------- 1 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64/jre/bin/java) *+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre/bin/java) 3 /usr/local/java/jdk1.8.0_161/bin/java 按 Enter 保留当前选项[+],或者键入选项编号:3