MVN package install error javac: invalid target release: 1.8

现象:
---------------------------------
[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.
The java that the system points to by default is inconsistent with the javac version.

At this point, if you want to use jdk1.7, use the alternatives --config java command.
[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:
※Select "2" to use the same version of java and javac as 1.7.0.

If you want to use 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
found java-1.7.0-openjdk-devel* in the system, but not java-1.8.0-openjdk-devel*

Use the alternatives tool to find that the linux system points to the javac version by default
[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
has no java-1.8.0 options.

To reduce trouble, uninstall 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

install 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

Mvn clean install on Maven Project is Build Success

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325259995&siteId=291194637