51

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+ Commented 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 Commented 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? Commented Jan 5, 2022 at 22:37
  • 1
    It's using Gradle Commented 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? Commented Jan 5, 2022 at 22:40

2 Answers 2

34

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.

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.

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

3 Comments

When I try this, I get the following error Unsupported class file major version 61
@user9847788 Did you also install Java 17?
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.
16

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 for Windows?

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 not, and you are trying to execute within the IDE

The problem might be 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.

5 Comments

AFAIK, IntelliJ always refers to the full java exe path defined in its own settings, and doesn't depend on OS environment
@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)
I've tried everything and I'm still getting this error. I messed with the system and user environment variables with every variation I could and it's still not working. It is a very strange error. I have to update the JRE to use pepk, yet when I try and update it, it says I have the latest version.
@PeterGriffin do two things for me: 1) Print out your path in the comments and 2) look in your Task Manager's "Details" tab and see if there are any applications running that may be causing this issue. If none these work, maybe I can give you my Skype and I can help you debug it that way.
@hfontanez I contacted Play Console support. This is the only app I haven't published with Play App Signing because I made it before that was an option. I had lost my keys, so they said there's nothing that can be done anyway except to make it in a new app and create a new store listing. I don't really like the app anyway, so I may just scrap it. I do appreciate your help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.