3

When i run my project i am getting the following exception:

javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: apache/commons/codec/UtilityUtil : Unsupported major.minor version 52.0 (unable to load class apache.commons.codec.UtilityUtil)

I have researched and found out that it happens if the version of java is different from runtime and compilation time.

I have followed these two posts and tried to figure out that i am using java 8 and runtime has 1.7.: Unsupported major.minor version 52.0 captive portal How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

I have changed the compilation version to 1.7. But still the same problem exists. I dont know why.

Runtime version: 1.7.0_45 Compilation Version: 1.7.0_80.

user513951
  • 12,445
  • 7
  • 65
  • 82
user7637864
  • 237
  • 3
  • 5
  • 15
  • 1
    as others noted, if you're compiling the codec library make sure the build sets targetCompatibility to be 1.7. On the other hand, if you're consuming the codec library as is (from Maven Central for example, or other binary repository) then the only thing you can do is upgrade your runtime to Java8 as you can't change the compiled binary. – Andres Almiray Mar 15 '17 at 21:03
  • I am pretty sure i am using java 1.7 but just to confirm is there a way to see the version of compilation used for the built? i confirmed i am using 1.7 by seeing: project--> properties-->java build path(made sure using jre 1.7) project-->properties-->Java Compiler (1.7) Here. @aalmiray – user7637864 Mar 15 '17 at 21:15
  • 1
    The problem may not be on your compiler setup but in the binaries you're consuming as dependencies. Check the Apache codec dependency with https://github.com/zeroturnaround/bad-classes. If it tells you it uses 52 (Java8 most likely based on the exception) then you either run your code with 1.8 _or_ download a copy of Apache Codec in source and compile it with 1.7 if possible, then set it as a dependency on your project. – Andres Almiray Mar 16 '17 at 08:19

4 Answers4

11

This is a duplicate. The classes you are using are probably compiled with Java 1.8 and your jvm is 1.7. That also includes 3rd party jars

bichito
  • 1,406
  • 2
  • 19
  • 23
  • I have made a re build and deployed the latest into server. So all the classes must compile using the latest version right? – user7637864 Mar 15 '17 at 21:01
  • Wooops, sorry for my answer! you were faster than me :) +1 – Luca D'Amico Mar 15 '17 at 21:02
  • But third party jars are not rebuilt – bichito Mar 15 '17 at 21:07
  • Thanks a lot for your response.Sorry for asking you this, but how do i rebuild third party files @efekctive. – user7637864 Mar 15 '17 at 21:12
  • Hi @efekctive. You are correct. I have used echo to print the java version while building.It printed : [echo] Java/JVM version: 1.8 [echo] Java/JVM detail version: 1.8.0_73. I am not really sure how to change that to 1.7 :( as i ahve changed the compilation version to 1.7 and removed the JRE 8 and included jre 7. – user7637864 Mar 15 '17 at 21:27
2

52 = J2SE 8. You are still compiling with Java 1.8 (or some libs you are using are compiled with 1.8 as pointed out by @efekctive).

Please post what command are you using to build.

Luca D'Amico
  • 3,192
  • 2
  • 26
  • 38
2

As @efekctive stated my build is using java 8 for building the class. Changed the version back to 7 and worked as expected. Thanks everyone.

user7637864
  • 237
  • 3
  • 5
  • 15
2

Please do the following steps to find out yourJRE version and JDK version.

JRE check

java -version

java version "1.7.0_111" OpenJDK Runtime Environment (IcedTea 2.6.7) (7u111-2.6.7-2~deb7u1) OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode)

JDK check

javac -version

javac 1.6.0_38

And you can find that both the versions are different. So, make them into common version. That will solve your issue.

RKA
  • 308
  • 2
  • 10