Skip to content
Advertisement

Java ClassVersionError although version seems to be okay

I’m getting the following error in my java web app (The application launches okay but when I click a button following error occurs). I’m using Tomcat (7.0.109) to run this application.
java.lang.UnsupportedClassVersionError: FileDetailsServlet has been compiled by a more recent
version of the Java Runtime (class file version 59.0), this version of the Java Runtime only
recognizes class file versions up to 52.0 (unable to load class [FileDetailsServlet])

Previously I used Java 15 (class version 59.0). But then I switched to JDK and JRE 1.8.0_311 (class version upto 52.0)because of other 3rd party apps.

Here are some things that I did

  1. I’ve checked class version of FileDetailsServlet class using this
    javap -verbose FileDetailsServlet| findstr "major"
    command. And it shows that version is 51.0 (Java 7).
  2. I’ve set JDK compliance to 1.8 in eclipse. (Project specific settings)
  3. After changing JDK I recompiled all the files using JDK 1.8.0_311
  4. I’ve checked environment variables. JAVA_HOME is “C:Program FilesJavajdk1.8.0_311” JRE_HOME is “C:Program FilesJavajre1.8.0_311” and Path is “C:Program FilesJavajdk1.8.0_311bin”

Am I missing anything? I can not go back to Java 15. So is there any way around?

Advertisement

Answer

Check your class path for any “leftovers” from the old system. It looks like you are not inspecting the correct files. Maybe you have the FileDetailsServlet in a wrong version as depencency somewhere, or just in a “standalone” JAR- or WAR-file.

It is also important that Eclipse settings alone will maybe not cover, how the used container serves the servlet, so which technology do you use to run the FileDetailsServlet? That’s the crucial point: this thing that you use to run (Tomcat, Jetty, other container, maybe included in a fat WAR or fat JAR file from Sprint Boot or another similar technology) has to use the correct .class file.

As you are using Tomcat as container: You should check the class files inside the folder webapps/appname folder below your tomcat folder (replace appname with the deployment context name) Take care: when you run tomcat from Eclipse this could be somewhere completely different than the installation folder on disk, but I don’t have an Eclipse installation ready to check that.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement