28

I am trying to run a Spring Boot app in IntelliJ.

But when I try to run I get the following error message:

Exception in thread "main" java.lang.UnsupportedClassVersionError: myProject 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

Here is the JRE location under my Run Configuration:

enter image description here

I have tried installing a couple of different Java versions here:

enter image description here

Here are my current system / environment variables:

Environment Variables:

JAVA_HOME: C:\Program Files\Java\jdk-11.0.12\bin

System Variables:

Path: C:\Program Files\Java\jdk-11.0.12\bin ....

I tried to find a JRE that matched the version, but haven't been able to find it.

Can someone please tell me what changes I need to make so I can successfully run this application locally?

14
  • 2
    Did you try changing the JRE location under "Run Configuration"? It says 1.8 now and you need it to be 11+ Jan 5, 2022 at 22:31
  • 2
    Sure. The distinction between them was removed after Java 8. You still don't need both. The JDK includes the JRE, so you do not have to download both separately Jan 5, 2022 at 22:34
  • 1
    Regardless, there is other information that is missing. Are you using Maven/Gradle? Is that compiling your code to Java11? Then IntelliJ's run config is set to Java8? Jan 5, 2022 at 22:37
  • 1
    It's using Gradle Jan 5, 2022 at 22:38
  • 2
    Okay, and do you see a line that has something like sourceCompatibility 11? Or targetCompatibility 11? Can you change that to 8 and run it? Jan 5, 2022 at 22:40

2 Answers 2

24

Open IntelliJ on your project and go to File >> Project Structure >> Project and on the option Project SDK Select java 11 and apply the changes.

Intellij Project structure

Edit--------

Then try these options on File >> Settings.

1.Set Gradle JVM Home Gradle JVM

2.Set the JDK version in the Project module settings JDK version in the Project module

3.Check the JDK version in the Modules version in the Modules

Close IntelliJ and open it again.

3
  • When I try this, I get the following error Unsupported class file major version 61 Jan 5, 2022 at 22:58
  • @user9847788 Did you also install Java 17? Jan 5, 2022 at 23:18
  • probably you need to configure java 17 on intelliJ on that same window settings, the project is asking for it, that depends on how you configure your gradle file. Jan 5, 2022 at 23:38
6

If you are trying to execute the code outside your IDE...

The problem is Windows....

Open your command prompt and type "where java". When you do this, you will notice a "weird" path that looks something like this

C:\Program Files\Common Files\Oracle\Java\javapath\java.exe

I can't recall what Windows version introduced this shortcut, but I want to say it was Windows 7. The problem is that this shortcut points to a Runtime Environment that is more recent (newer) than the Java version that was used to compile the code. In other words, Java is backwards compatible; not forward compatible. Compiled code cannot run in a newer Java version.

How do you fix this?

One way is to go to your SYSTEM Environment Variables and edit the Path system variable and add JAVA_HOME at the very beginning of the paths. It will be something like this

%JAVA_HOME%; {YOUR OTHER PATHS HERE}

If you are trying to execute within the IDE, the problem is similar. POTENTIALLY, you can have a conflict between your PROJECT properties and your global IDE properties, where the Runtime Environment points to a newer version of Java than the JDK used to compile. That said...

I had a very weird issue with an application I worked on years ago. It was a client/server application and a coworker of mine was having this issue because, unbeknownst to her, there was version of the server running in the background that was causing the conflict. So, if you have a similar type of application, check your processes using Task Manager and make sure you either 1) shutdown this application and try again, or 2) Uninstall that application and reinstall the new one. In her case, she tried rebooting her PC but that didn't work because the process would start automatically after each reboot.

2
  • AFAIK, IntelliJ always refers to the full java exe path defined in its own settings, and doesn't depend on OS environment Jan 5, 2022 at 22:39
  • @OneCricketeer I don't know much about IntelliJ per se, but I helped a coworker fixed a similar problem about 5 years ago. I edited my answer with this strange edge case, just in case. Our issue baffled us for almost an entire day (believe it or not)
    – hfontanez
    Jan 5, 2022 at 22:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.