Spring Boot Error

  1. Exception in thread "main" java.lang.UnsupportedClassVersionError: 

\Latest\service\target>java -jar -Dspring.profiles.active=dev abc-service-0.0.1-SNAPSHOT.jar

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/../AbcServiceApplication has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

        at java.lang.ClassLoader.defineClass1(Native Method)

==>

A Look at the ErrorLet's start by looking at an example error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/baeldung/MajorMinorApp 
  has been compiled by a more recent version of the Java Runtime (class file version 55.0), 
  this version of the Java Runtime only recognizes class file versions up to 52.0

This error is telling us that our class was compiled at a higher version of Java than the version with which we tried to run it. More specifically, in this case we compiled our class with Java 11 and tried to run it with Java 8.

2.1. Java Version NumbersFor reference, let's take a quick look at the Java version numbers. This will come in handy in case we need to download the appropriate Java version.

The major and minor version numbers are stored in the class bytecode at bytes six and seven.

  Let's see how the major version numbers map to Java versions:

  • 45 = Java 1.1
  • 46 = Java 1.2
  • 47 = Java 1.3
  • 48 = Java 1.4
  • 49 = Java 5
  • 50 = Java 6
  • 51 = Java 7
  • 52 = Java 8
  • 53 = Java 9
  • 54 = Java 10
  • 55 = Java 11
  • 56 = Java 12
  • 57 = Java 13

3. Fix via the Command Line Now let's discuss how we can resolve this error when running Java from the command line.

Depending on our situation, we have two ways we can resolve this error: compile our code for an earlier version of Java, or run our code on a newer Java version.

The final decision depends on our situation. If we need to use a third-party library that's already been compiled at a higher level, our best option is probably to run our application using a newer Java version. If we're packaging an application for distribution, it might be best to compile down to an older version.

No comments:

Post a Comment