【问题标题】:Spring Boot Multi-Module maven project repackage failedSpring Boot Multi-Module maven 项目重新打包失败
【发布时间】:2019-12-02 21:11:47
【问题描述】:

我目前正在关注 John Thompson 的 Spring Framework Beginner to Guru 课程。我按照他的一步一步的程序,在 Spring Boot 上为 Spring Pet Clinic 创建多模块 Maven 项目。当我单击根模块上的包时,它说重新打包失败,无法找到主类。

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </execution>
        </executions>
        </plugin>
    </plugins>
</build>

[错误] 无法执行目标 org.springframework.boot:spring-boot-maven-plugin:2.1.6.RELEASE:repackage (repackage) on project pet-clinic-data: 执行目标 org.springframework 的重新打包。 boot:spring-boot-maven-plugin:2.1.6.RELEASE:repackage failed: Unable to find main class -> [Help 1]

【问题讨论】:

    标签: java spring-boot spring-mvc multi-module spring-boot-maven-plugin


    【解决方案1】:

    删除

     <configuration>
           <skip>true</skip>
       </configuration>
    

    并添加“spring-boot.repackage.skip”属性,如下所示:

    <artifactId>pet-clinic-data</artifactId>
        <properties>
            <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
        </properties>
    

    【讨论】:

      【解决方案2】:

      spring-boot-maven-plugin 应该只在包含主类的模块的 pom.xml 中。看起来你在一个简单的 jar 模块上(或继承)了这个插件,主模块将用作依赖项。

              <plugin>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-maven-plugin</artifactId>
              </plugin>
      

      主类使用@SpringBootApplication注解

      【讨论】:

        【解决方案3】:

        您正在使用 spring-boot-maven-plugin:2.1.6.RELEASE。

        从 Spring-Boot 2 开始,您不再需要 Spring Boot 插件。

        您可以在声明模块的工件 id 后使用以下代码。

        <artifactId>pet-clinic-data</artifactId>
        <properties>
            <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
        </properties>
        

        【讨论】:

        • spring-boot-maven-plugin 至少对于使用 Spring Boot v2.1.7.RELEASE、Spring v5.1.9.RELEASE 运行的应用程序仍然是必需的。如果我注释掉插件,我的应用程序将失败,并显示“在 .jar 中没有主清单属性”。
        【解决方案4】:

        错误不言自明。执行者找不到你的主类。它与您的 pom.xml 无关。但与您用于构建和运行 Spring Boot 项目的环境有关。

        如果您使用 IntelliJ,请转到Run/Debug configuration(屏幕截图上的Add configuration,在您的情况下可能是其他内容)并确保您的主类退出。然后点击你的班次两次并输入Invalidate Caches/Restart,然后两者都做。然后它应该按预期工作。

        【讨论】:

          猜你喜欢
          • 2023-01-31
          • 1970-01-01
          • 2022-06-10
          • 1970-01-01
          • 2021-06-15
          • 2015-08-01
          • 2020-06-09
          • 2020-03-09
          • 1970-01-01
          相关资源
          最近更新 更多