0

i'm trying to run a project from Spring Initializr and I am getting the error java.lang.UnsupportedClassVersionError when I try to run the Main. The complete error is java.lang.UnsupportedClassVersionError: has been compiled by a more recent version of the Java Runtime (class file version 62.0), this version of the Java Runtime only recognizes class file versions up to 55.0. The gradle is set to jvmTarget = 18 but aparrently when I put it to 11 it seem to fix the problem. I want to know why when I downgrade the version the program work.

5
  • Seems you execute programs with JDK version lower than version used for build. Commented Aug 8, 2022 at 8:52
  • The problem is than 18 > 11 but 11 works and 18 not. Commented Aug 8, 2022 at 8:54
  • which version of gradle are you using ? https://docs.gradle.org/current/userguide/compatibility.html Commented Aug 8, 2022 at 8:56
  • I'm using gradle version 7.5. Which is compatible with java 18. Commented Aug 8, 2022 at 9:02
  • which JDK are you using in your IDE ? In your global settings ? And in your project structure ? Commented Aug 8, 2022 at 9:12

2 Answers 2

1

This error shows that you use older JRE version to run than to build. Your setup in gradle, you have to check what is your runtime version.

It seems you use IntelliJ. Go to File > Project Structure > Project > SDK - check if you have the Java 18 set here. You can also check in Run Configuration if there is proper JVM set.

Check also the JAVA_HOME env variable and set this variable to point to your recent JDK.

Sign up to request clarification or add additional context in comments.

1 Comment

I had 3 directories, 1.8 18 and jbr-11, I change the path of jbr-11 to the path of jdk 18 and it fix the problem! But thank you so much!
0

I finally fixed the problem, I had to change the jetbrains runtime in project structure to the jdk 18 path. Aparently it fix the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.