简体   繁体   English

JDK 8的Maven问题:不支持的major.minor版本52.0

[英]Maven trouble with JDK 8 : Unsupported major.minor version 52.0

Apologies if my question is a duplicate of any other items previously mentioned here . 抱歉,如果我的问题是这里前面提到的任何其他项目的重复。

I have the following configuration : 我有以下配置:

Ubuntu 14.04 64 bit JDK 1.8u45 Maven v3.3 Ubuntu 14.04 64位JDK 1.8u45 Maven v3.3

I am trying to package my code into a deployable war. 我试图将我的代码打包成可部署的战争。

The war gets created succesfully , but on accessing it on my browser , I am running into Unsupported major.minor version 52.0 errors. 战争成功创建,但是在浏览器中访问战争时,我遇到了不支持的major.minor 52.0版本错误。

On Googling around I saw that this is due to a mismatch in installed JDK and the maven-compiler level. 在Googling上,我看到这是由于已安装的JDK和maven-compiler级别不匹配所致。

But in my case , both are the same. 但就我而言,两者是相同的。 -> JDK 1.8 and maven-compiler version 3.3 with source and target 1.8. ->具有源和目标1.8的JDK 1.8和maven-compiler版本3.3。

What can I do to get my build to compile successfully ? 我该怎么做才能使我的构建成功编译?

Outputs of some helpful commands : 一些有用的命令的输出:

mvn -v mvn -v

root@labuser-OptiPlex-3010:/# mvn -v 
Maven home: /usr/local/apache-maven-3.3.3 
Java version: 1.8.0_45, vendor: Oracle Corporation 
Java home: /usr/local/jdk1.8.0_45/jre Default locale: en_IN, platform encoding: UTF-8 OS name: "linux", version: "3.16.0-43-generic", arch: "amd64", family: "unix" 

mvn -v will tell you what Java version maven is using. mvn -v会告诉您maven使用的Java版本。 Run that in your console, it will probably show you that it uses the wrong Java version. 在您的控制台中运行它,它可能会向您显示它使用了错误的Java版本。

Since you mentioned you can successfully create the war with maven, it sounds like JDK 8 is being used as expected during the build. 既然您提到可以成功使用Maven创建战争,这听起来像在构建过程中按预期使用了JDK 8。 The problem is your server is apparently running using an older version of Java. 问题是您的服务器显然正在使用旧版本的Java运行。 Although you only installed JDK 8 yourself, you must have already had an older version of Java on your computer. 尽管您自己只是安装了JDK 8,但是您必须在计算机上安装了旧版本的Java。 Make sure JAVA_HOME is set to JDK 8 and that your server sees that version properly. 确保将JAVA_HOME设置为JDK 8,并且您的服务器可以正确看到该版本。 See if you have a JRE_HOME env variable set as well, and point it to JDK 8 as well. 查看是否还设置了JRE_HOME env变量,并将其也指向JDK 8。

I got the solution by running :

<tomcat-root-dir> / bin > catalina.bat version.

It showed that the JDK on my machine was JDK1.7 where as the one used to compile the WAR was 1.8. 结果表明,我机器上的JDK是JDK1.7,而用于编译WAR的JDK是1.8。

Thanks to everyone for their inputs. 感谢大家的投入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM