当前位置: 首页 > 知识库问答 >
问题:

UnsupportedClassVersionError:已由Java运行时的最新版本(类文件版本55.0)编译,此版本(..)至52.0

贾烨
2023-03-14

我正在尝试启动我为Spring Boot项目构建的jar文件。首先我做了:

mvn clean package spring-boot:repackage

然后,我尝试启动jar文件,但出现以下错误:

线程“main”Java.lang.UnsupportedClassVersionError中出现异常:IT/sysdata/Helios_BackEnd_Admin/HeliosAdminBackEndApplication已由较新版本的Java运行时(类文件版本55.0)编译,此版本的Java运行时仅识别52.0以下的类文件版本:Java.lang.ClassLoader.DefineClass1(本机方法)Java.lang.ClassLoader.DefineClass(未知源)Java.security.SecureClassLoader.DefineClass(未知源)PringFramework.boot.loader.MainMethodRunner.Run(MainMethodRunner.java:46)在org.springFramework.boot.loader.launcher.launch(launcher.java:87)在org.springFramework.boot.loader.launcher.launch(launcher.java:50)在org.springFramework.boot.loader.jarLauncher.main(jarLauncher.java:51)

我检查了一下,到处都是java版本11(至少从我所看到的)。这是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>

这些是我在Project属性->Java编译器->JDK遵从性下的设置:

然后在窗口->首选项->已安装的JRes:

共有1个答案

阎建华
2023-03-14

你可以尝试添加下面的maven编译器插件并检查。

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

运行maven并构建jar并尝试运行。

 类似资料: