标签:
现象:
---------------------------------
[ERROR] Failure executing javac, but could not parse the error:
javac: invalid target release: 1.8
Usage: javac <options> <source files>
use -help for a list of possible option
---------------------------------
调查发现:
[root@localhost ~]# java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)
[root@localhost ~]# javac -version
javac 1.7.0_111
即java与javac版本不一致。
[root@localhost ~]# which java
/usr/bin/java
[root@localhost ~]# which javac
/usr/bin/javac
[root@localhost ~]# ll /usr/bin/java
lrwxrwxrwx. 1 root root 22 Oct 7 10:49 /usr/bin/java -> /etc/alternatives/java
[root@localhost ~]# ll /usr/bin/javac
lrwxrwxrwx. 1 root root 23 Oct 7 10:49 /usr/bin/javac -> /etc/alternatives/javac
使用alternatives工具发现linux系统默认指向java/javac版本
[root@localhost ~]# alternatives --display javac
javac - status is auto.
link currently points to /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111-2.6.7.2.el7_2.x86_64/bin/javac
.................
Current `best‘ version is /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111-2.6.7.2.el7_2.x86_64/bin/javac.
[root@localhost ~]# alternatives --display java
java - status is auto.
link currently points to /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/jre/bin/java
.................
Current `best‘ version is /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/jre/bin/java.
系统默认指向的java与javac版本不一致。
此时,如果希望使用jdk1.7,则使用alternatives --config java命令。
[root@localhost ~]# alternatives --config java
There are 2 programs which provide ‘java‘.
Selection Command
-----------------------------------------------
1 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111-2.6.7.2.el7_2.x86_64/jre/bin/java
*+ 2 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/jre/bin/java
Enter to keep the current selection[+], or type selection number:
※选择“2”即可使用java与javac版本同为1.7.0。
如果希望使用jdk1.8,
[root@localhost ~]# rpm -qa | grep java
java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.2.el7_2.x86_64
python-javapackages-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
tzdata-java-2015g-1.el7.noarch
java-1.7.0-openjdk-devel-1.7.0.111-2.6.7.2.el7_2.x86_64
java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
java-1.7.0-openjdk-1.7.0.111-2.6.7.2.el7_2.x86_64
javapackages-tools-3.4.1-11.el7.noarch
发现系统中有java-1.7.0-openjdk-devel*,而没有java-1.8.0-openjdk-devel*
使用alternatives工具发现linux系统默认指向javac版本
[root@localhost ~]# alternatives --config javac
There is 1 program that provides ‘javac‘.
Selection Command
-----------------------------------------------
*+ 1 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111-2.6.7.2.el7_2.x86_64/bin/javac
没有java-1.8.0的可选项。
为了减少麻烦,先卸载java-1.7.0
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.2.el7_2.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-devel-1.7.0.111-2.6.7.2.el7_2.x86_64
[root@localhost ~]# rpm -e --nodeps tzdata-java-2015g-1.el7.noarch
安装java-1.8.0-openjdk-devel*
[root@localhost ~]# yum -y install java-1.8.0-openjdk-devel*
[root@localhost ~]# java -version
openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
[root@localhost ~]# javac -version
javac 1.8.0_102
对Maven Project 进行mvn clean install即Build Success
Refer to:http://www.cnblogs.com/kreo/p/4308651.html
MVN package install error javac: invalid target release: 1.8
标签:
原文地址:http://www.cnblogs.com/linprogram/p/5936520.html