【已解决】this version of the Java Runtime only recognizes class file versions up to 52.0

1 报错问题

在把springboot项目打包了jar之后,准备本地运行一下

java -jar xxx-0.0.1-SNAPSHOT.jar

然后报错:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/example/myweb/xxxApplication 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 52.0

2 可能的原因

  1. 编译版本和运行版本不一致,可能是编译版本高于运行版本导致的

修改pom.xml, 将此版本改为java -version版本

    <properties>
        <java.version>11</java.version>
    </properties>
  1. spring-boot-maven-plugin增加<parent>的版本号

如果没指定spring-boot-maven-plugin 的版本,就会拿取最新的版本打包,但是目前高版本的为未必适合1.8的jdk,如果它确实是您想要用于 spring boot 项目的版本。

为了解决这个问题,就必须明确指定spring-boot-maven-plugin的版本。

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>2.7.9</version> //增加<parent>的版本号
    </plugin>

3 重新打包,运行

两种方式都尝试了一下,可以运行了!

如果运行遇到端口被占用的问题

  1. 输入netstat -lnp命令查看端口信息

  1. 使用sudo kill xxx进行删除


参考链接:

this version of the Java Runtime only recognizes class file versions up to 55.0 at ...

Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file

猜你喜欢

转载自blog.csdn.net/baidu_30506559/article/details/129622498