简体   繁体   中英

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

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.

On Googling around I saw that this is due to a mismatch in installed JDK and the maven-compiler level.

But in my case , both are the same. -> JDK 1.8 and maven-compiler version 3.3 with source and target 1.8.

What can I do to get my build to compile successfully ?

Outputs of some helpful commands :

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. Run that in your console, it will probably show you that it uses the wrong Java version.

Since you mentioned you can successfully create the war with maven, it sounds like JDK 8 is being used as expected during the build. The problem is your server is apparently running using an older version of Java. Although you only installed JDK 8 yourself, you must have already had an older version of Java on your computer. Make sure JAVA_HOME is set to JDK 8 and that your server sees that version properly. See if you have a JRE_HOME env variable set as well, and point it to JDK 8 as well.

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.

Thanks to everyone for their inputs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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