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

时间:2019-05-21 09:43:30

标签: java maven spring-boot executable-jar maven-jar-plugin

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

mvn clean package spring-boot:repackage

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

  

线程“主”中的异常java.lang.UnsupportedClassVersionError:   它/ sysdata / helios_backend_admin / HeliosAdminBackendApplication已被   由Java Runtime的更新版本编译(类文件   版本55.0),此版本的Java运行时仅识别类   文件版本最高为52.0           在java.lang.ClassLoader.defineClass1(本机方法)           在java.lang.ClassLoader.defineClass(未知来源)           在java.security.SecureClassLoader.defineClass(未知来源)           在java.net.URLClassLoader.defineClass(未知来源)           在java.net.URLClassLoader.access $ 100(未知源)           在java.net.URLClassLoader $ 1.run(未知源)           在java.net.URLClassLoader $ 1.run(未知源)           在java.security.AccessController.doPrivileged(本机方法)           在java.net.URLClassLoader.findClass(未知来源)           在java.lang.ClassLoader.loadClass(未知来源)           在org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)           在java.lang.ClassLoader.loadClass(未知来源)           在org.springframework.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>

这些是我在项目Properties -> Java Compiler -> JDK Compliance下的设置:

enter image description here

然后在Window-> Preferences -> Installed JREs中输入

enter image description here

更新

这些设置可以吗? enter image description here

3 个答案:

答案 0 :(得分:0)

可以尝试添加以下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,然后尝试运行。

答案 1 :(得分:0)

真正的问题是,您之前通过升级版本的 JDK 构建了类,而不是您目前拥有的版本。

我也遇到了类似的问题,我通过以下步骤在 Eclipse 中解决了这个问题:

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.

答案 2 :(得分:0)

我通过设置 JAVA_HOME 环境变量将其指向我机器上的 jdk12 目录来修复。