Usr
Usr

Reputation: 2848

UnsupportedClassVersionError: has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version (..)up to 52.0

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:

enter image description here

Then in Window-> Preferences -> Installed JREs:

enter image description here

UPDATE

Are these settings ok? enter image description here

Upvotes: 18

Views: 130801

Answers (10)

Saurabh Siwa
Saurabh Siwa

Reputation: 1

For me the issue is related to the Maven classpath, IDE by default uses maven bundled or wrapper. you can try these steps:

Locate the Maven folder: Identify the folder where you have downloaded and extracted Apache Maven. Let's assume the path to the Maven folder is C:/apache-maven/apache-maven-3.9.3.

Set the Maven home path in your IDE:

For IntelliJ IDEA:

  1. Go to "File" -> "Settings" (or "Preferences" on macOS).
  2. In the Settings/Preferences dialog, navigate to "Build, Execution, Deployment" > "Build Tools" > "Maven".
  3. In the "Maven home directory" field, enter the path C:/apache-maven/apache-maven-3.9.3. 4.Click "Apply" and then "OK" to save the changes.

For Eclipse:

  1. Go to "Window" > "Preferences".
  2. In the Preferences dialog, navigate to "Maven" > "Installations".
  3. Click on "Add" to add a new Maven installation.
  4. In the "Directory" field, browse and select the Maven folder (C:/apache-maven/apache-maven-3.9.3).
  5. Click "Finish" to save the Maven installation.
  6. Select the newly added Maven installation in the list and click "Apply" and then "OK".
  7. Rebuild your Maven project: After setting the Maven home path, rebuild your Maven project to ensure that the updated Maven configuration takes effect.

Upvotes: 0

geekyouth
geekyouth

Reputation: 350

    <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${spring-boot.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Upvotes: -1

Kıvılcım
Kıvılcım

Reputation: 419

Since you did not specift plugin version in pom.xml file, it will always go for the latest version. Which is 3.0.0 as of 24 Nov 2022. And it requires Java 17 at least.

So, if your project is lower than Java 17, it wont work.

What I suggest is please use the plugin with the same version of your java project. And specify it in pom.xml.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>your projects java version here.</version>
</plugin>

Upvotes: 3

Pranab Kumar Nath
Pranab Kumar Nath

Reputation: 21

After configuring the version of the compiler to 1.8 (your required version), try the older version of spring boot currently it is 3.0.0 by default but you can try 2.7.6 instead.

enter image description here

Upvotes: 2

Marko
Marko

Reputation: 181

In my case, there was a wrong JAVA_HOME setup,
and for me worked the following steps:

  1. Go to Environment Variables
  2. Click Edit when JAVA_HOME is selected
  3. Select the directory where your desired jdk is instaled

This might help to select the correct Java version:

  • Java 1.2 uses major version 46
  • Java 1.3 uses major version 47
  • Java 1.4 uses major version 48
  • Java 5 uses major version 49
  • Java 6 uses major version 50
  • Java 7 uses major version 51
  • Java 8 uses major version 52
  • Java 9 uses major version 53
  • Java 10 uses major version 54
  • Java 11 uses major version 55
  • Java 12 uses major version 56
  • Java 13 uses major version 57
  • Java 14 uses major version 58
  • Java 15 uses major version 59
  • Java 16 uses major version 60
  • Java 17 uses major version 61
  • Java 18 uses major version 62
  • Java 19 uses major version 63

Upvotes: 18

RyanNeedSleep
RyanNeedSleep

Reputation: 159

Just go find the right java JDK and install it, in your case (55.0 ~ JDk 11) This should work, at least for me.

Upvotes: 1

Scot
Scot

Reputation: 379

I had similar issues running mvn org.springframework.boot:spring-boot-maven-plugin:run on the command line. It turns out the plugin version was upgraded to something that no longer supports the version of java I was running ( java 11 ). Here is the ERROR I saw:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.0-M1:run (default-cli) on project PROJECT_NAME: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:3.0.0-M1:run failed: Unable to load the mojo 'run' in the plugin 'org.springframework.boot:spring-boot-maven-plugin:3.0.0-M1' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: org/springframework/boot/maven/RunMojo has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

I was able to fix this by specifying the version in the command line mvn org.springframework.boot:spring-boot-maven-plugin:2.6.3:run ( notice :2.6.3 )

Upvotes: 9

Naveed I
Naveed I

Reputation: 21

I fixed by setting JAVA_HOME environment variable to point it to jdk12 directory on my machine.

Upvotes: 1

Papai from BEKOAIL
Papai from BEKOAIL

Reputation: 1539

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.

Upvotes: 6

Sambit
Sambit

Reputation: 8031

Can you try to add the below maven compiler plugin and check.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>11</release>
    </configuration>
</plugin>

run the maven and build the jar and try to run.

Upvotes: 2

Related Questions