Season of spring.
So, this is the second installment in the spring-boot series.
In the previous post, I showed you how to set up the first steps to build a spring-boot project. However, during the process, I faced some trouble working the spring project properly, especially UnsupportedClassVersionError, as the title indicates. So, here’s how I solved the issue.
The error:
So, this is the error message I’ve got.
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/SpringApplication has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 60.0
The error suggests that the current Java Runtime is running on Java version 17 (17 = 61.0) and my current Java version could be older than version Java 16 (16 = 60.0).
You can check the Java class file version corresponding cheat sheet from this link.
The solution:
In this case, the most practical solution is to install the latest LTS version of Java and set its path. Here’s what I did.
Go to this link and install the package that matches your OS.
After the installation, set its path.
Control Panel -> System and Security -> System -> Advanced Settings.
Then, set the path accordingly.
First, select Path in the user variables and click the Edit button.
Click the New button.
Go to Expoloror, and find the location where you installed Java 17, and copy its bin path. Usually, you find it in the following path.
C:\Program Files\Java\jdk-17\bin
Paste it here and click OK.
Do the same thing with system variables as well and save the settings.
Go to the command prompt (just type cmd), and type:
java -version
Then, you can confirm the path is successfully set.
Then, in my case, to confirm the problem is fixed, I opened my Eclipse project -> right-clicked the project name -> select properties.
Java compiler -> check the IDE’s compiling version, which is currently set as 16. As of this writing, 16 is the latest version you can choose on my environment. So, I left it as it is.
The result:
Then, I worked!!