Maven run configuration ignores JRE setting
Answered
The system default JDK on my computer is Java 8, however for a project I need to use Java 17.
I configured a Maven run configuration with a compile job and set the JRE to the installed JDK 17:

However, when I run this configuration (using the “Run” button), I get the following error in the console:
Exception in thread "main" java.lang.UnsupportedClassVersionError: jakarta/persistence/spi/PersistenceUnitInfo 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.0So it seems the IDE still users JDK 8 from the system default instead of the configured JDK 17.
Is this a bug or am I missing something?
I would like to add that I also have configured Java 17 in the project settings and as the boot JRE for the IDE.
Please sign in to leave a comment.
Hello!
Thank you for reporting this!
I believe this option sets JDK for the Maven itself (as it is a separate process that does need its' own JVM) and not the application.
Try changing the
SDKoption under Project Structure → Project.Hello Roman, thanks for your reply.
I did specify JDK 17 under “Project Structure” → Project, however that doesn't change anything about the error.
Maybe my initial post wasn't formulated clear enough; what I meant that the Maven Run itself fails at the
compilephase due to Maven using the system default JDK 8 for compilation instead of the JDK 17 configured in the run configuration.Exactly that's what I want to do, however the setting seems to be ignored.
My apologies for misunderstanding!
In that case your setup should be correct, except you seem to be using JetBrains Runtime, which is primarily intended for IDEA's internal usage and not for Maven or the applications.
Could you try using a regular JDK? Which version of IDEA do you currently have installed?
If the issue persists, would you be able to share your Maven Settings:
and, if possible, the Project itself for further investigation?
Hello Roman … I figured it out.
In my Maven setup, I had a configuration for exec-maven-plugin that spawned another java process which was of course using the system PATH to find the java executable, which pointed to the JDK 8.
Thanks for your support!