java - 使用 spring 版本 2.5.7 的 Spring Boot 无法使用 jdk 1.8 重新打包

标签 java spring-boot maven spring-boot-maven-plugin maven-package

运行 maven 包目标时

mvn clean package

构建抛出错误:

goal org.springframework.boot:spring-boot-maven-plugin:3.0.0-M1:repackage failed: Unable to load the mojo 'repackage' 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/RepackageMojo 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

我的 JAVA_HOME 指向 jdk1.8.0_73

如何让 spring-boot-maven-plugin 以重新打包的目标运行?

以下是我的模块中的 maven 构建配置。

<build>
<resources>
    <resource>
        <directory>resources</directory>
    </resource>
</resources>
<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
            <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
            <webResources>
                <resource>
                    <directory>src/main/resources</directory>
                    <include>*.*</include>
                    <targetPath>/WEB-INF/classes</targetPath>
                </resource>
                <resource>
                    <directory>src/main/webapp/errors</directory>
                    <include>*.*</include>
                    <targetPath>/errors/</targetPath>
                </resource>
            </webResources>
        </configuration>
    </plugin>

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <mainClass>com.services.MyAApp</mainClass>
            <layout>war</layout>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

</plugins>

最佳答案

你 pom.xml 中使用的“spring-boot-maven-plugin”插件的版本是 3.0.0-M1,只能用于 Java 17 或更高版本。切换到 2.5.7,如果它真的是你想用于 spring boot 项目的版本。

关于java - 使用 spring 版本 2.5.7 的 Spring Boot 无法使用 jdk 1.8 重新打包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71002476/

相关文章:

spring-boot - 如何使用Spring Boot将JSON数据文件导入到mongodb?

node.js - 加快 Node.js 项目的编译速度

javascript - AngularJS 1.6 升级代码登录不再适用于 REST?

eclipse - 如何将Maven项目拆分成不同的模块?

java - 如何为所有模块、java、android 应用程序和 android 库配置 sourceCompatibility 和 compilerArgs?

java - 是否可以向 API Explorer 中的 Cloud Endpoint Java 字段添加描述?

java - 从 Sonatype Staging 测试我的包

java - Maven Cobertura 插件生成不完整的覆盖率报告

java - 为什么我收到此错误 "EmbeddedServletContainerInitializedEvent cannot be resolved to a type"?

java - 配置 OCR JAVA Asprise