UnsupportedClassVersionError: has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version (..)up to 52.0
The real problem was, you built classes before by some upgraded version of JDK than what you currently have.
I too faced a similar issue, which I solved in Eclipse by following steps:
Project Properties (Alt + EnterKey) -> Java Build Path -> "Libraries" section ->
classpath -> select "JRE System Library" -> Edit -> Execution environment from "JRE System Library" window ->
Select the exact JDK version you currently have -> Apply -> Apply & Close.
Related videos on Youtube
Usr
Updated on July 09, 2022Comments
-
Usr almost 2 years
I'm trying to launch the jar file I've builded for my Spring Boot project. First I did:
mvn clean package spring-boot:repackage
then I've tried to launch the jar file, and I had the following error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: it/sysdata/helios_backend_admin/HeliosAdminBackendApplication 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 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93) at java.lang.ClassLoader.loadClass(Unknown Source) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46) at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
I've checked and java version is 11 everywhere (at least from what I saw). This is the pom:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>it.sysdata</groupId> <artifactId>helios_backend_admin</artifactId> <version>0.0.1-SNAPSHOT</version> <name>helios-admin-backend</name> <packaging>jar</packaging> <description>Helios Backend for Dashboard admin</description> <properties> <java.version>11</java.version> <flowable.version>6.4.1</flowable.version> <swagger.version>2.9.2</swagger.version> <jwt.version>0.9.1</jwt.version> <cron4j.version>2.2.5</cron4j.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- Flowable --> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter-process</artifactId> <version>${flowable.version}</version> </dependency> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-http</artifactId> <version>${flowable.version}</version> </dependency> <!-- Swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${swagger.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger.version}</version> </dependency> <!-- JWT --> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>${jwt.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>3.10.1</version> </dependency> <dependency> <groupId>it.sauronsoftware.cron4j</groupId> <artifactId>cron4j</artifactId> <version>${cron4j.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> </dependency> </dependencies> <build> <finalName>${artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <source>11</source> <target>11</target> </configuration> </plugin> </plugins> </build> </project>
These are my settings under Project
Properties -> Java Compiler -> JDK Compliance
:Then in
Window-> Preferences -> Installed JREs
:UPDATE
-
Stephen C almost 5 yearsThe JDK that is being used to run your application is Java 8. Some of the classes have been built using Java 11. Use Java 11 to run the application. The problem is not in the POM files or the JARs your IDE's compiler configs. The problem is how you are running it.
-
Usr almost 5 yearsSo I have to set jdk to 11 and not use jre 11 like now?
-
David Pérez Cabrera almost 5 yearsWindow-> Preferences -> Installed JREs set jdk to 11 not to jre 1.8 as StephenC said.
-
Stephen C almost 5 years1) JDK and JRE are equivalent when you are running code. 2) There is no JRE in Java 11. They stopped shipping JREs in the Java 11 release. (Oracle JDK and Open JDK both)
-
Usr almost 5 yearsHi, I've done this, re-run the maven command and then java -jar, but it's giving me the same error.
-
Stephen C almost 5 yearsWhat has maven got to do with this? This is about running the code. Not building it. Type
java -version
. What does it say? I bet you its says Java 8! -
Usr almost 5 yearsI want to build a jar and then run it, but when doing java -jar it's giving the error. I've updated the question with the suggested edit, but still not working, it is right like that?
-
Usr almost 5 years@StephenC java -version actually tells it's 8. But I've set JAVA_HOME as
C:\Program Files\Java\jdk-11.0.2
and in Path I have bothC:\Program Files\Java\jdk-11.0.2\bin
andC:\Program Files\Java\jdk1.8.0_201\bin
-
Stephen C almost 5 yearsIf you are running the application from the command line, then the "installed JREs" settings in your IDE are not relevant.
-
Usr almost 5 yearsI've set it. I've said it in the comment above.
-
Stephen C almost 5 yearsAnd I bet you have either set it incorrectly, or you didn't set it in the command shell you are using to launch your app. But I can guarantee that this is the reason you are getting Java 11 not Java 8.
-
Usr almost 5 yearsJava 8 is indeed in front...
-
Stephen C almost 5 yearsThen you didn't restart your shell after setting it. Type
echo %PATH%
. Does it say the right thing? -
Usr almost 5 yearsNo I've restarted it. It keeps saying it's java 8. I've deleted jdk 8 from path but still doing this
-
Stephen C almost 5 yearsArghh ... you want Java 11 ... so Java 11 must be ahead of Java 8
-
Stephen C almost 5 yearsWhich is already ahead? You have said that both are ahead now.
-
Usr almost 5 yearsAs I've said, it is already ahead. And also, I've deleted Java 8 from path to exclude the problem, restarted the shell, but keeps saying it's java 8
-
Stephen C almost 5 yearsIf the bin directory containing
java
for Java 8 is not on the shell's PATH then runningjava -version
from the shell's command prompt cannot possibly tell you that you are running Java 8. Unless you have done something crazy like dropped symlink tojava
in some directory earlier in the path. Or created a shell alias forjava
. Or created a BAT file calledjava.BAT
. But this is all basic "how does the Windows shell work" stuff. -
Krishnom almost 5 yearsCan you please provide your run configurations? Which IDE you are using(eclipse or IDEA)?
-
-
Elydasian almost 3 yearsPlease provide a detailed explanation to your answer, in order for the next user to understand your answer better.
-
Naveed I almost 3 yearsI have expanded my answer. Thanks.
-
Jeremy Thompson almost 2 yearsInstructions with pictures stackoverflow.com/a/72455961/495455