解决:Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.2.1.RELEASE:repackage failed: Unable to find main class

这个大坑整了我一晚上,现在解决了做个总结:
首先我们看报错原因,为什么会说不能找到主类?其次我们定位一下我们项目中配了spring-boot-maven-plugin:2.2.1.RELEASE的位置。

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

1.首先理解这段代码的作用:spring-boot-maven-plugin插件是将springboot的应用程序打包成fat jar的插件。spring boot 借助spring-boot-maven-plugin将所有应用启动运行所需要的jar都包含进来,从逻辑上将具备了独立运行的条件。
2.spring-boot-maven-plugin打包条件:会去扫描项目的main方法,也就是说,引入改配置,你就需要在src/java/mian下写一个启动类。

好,知道了前提引入我的开发环境。
在这里插入图片描述
如图,父子项目中,只有service下的两个项目为可执行jar包,其他的都不可执行。错就错在在主类添加了spring-boot-maven-plugin插件,导致install项目时,去扫描了model、common等不可执行的文件。

解决:将父类中的spring-boot-maven-plugin插件注释掉,并确保子项目不可执行项目中没有spring-boot-maven-plugin插件配置。
在这里插入图片描述
(resource内的内容为将配置文件一块打包)

至此,我们reload后再clean、install试试。
在这里插入图片描述
成功!

多嘴说一句:开发搭环境的时候不要盲目的配置插件,要了解该插件是否满足自己的开发需求。

贴上一篇给我启发的文章链接:
https://blog.csdn.net/qq_41264674/article/details/106539584

以上仅满足解决个人的开发问题,大家仅作参考,若有说的不正确的地方欢迎指出。谢谢!继续去刚代码了。

GitHub 加速计划 / ma / maven
36
3
下载
Maven: Apache Maven是一个开源的项目管理和构建工具,主要用于Java项目。适合需要自动化项目构建和依赖管理的开发者。特点包括约定优于配置、易于使用和社区驱动。
最近提交(Master分支:3 个月前 )
fb619297 Bumps [org.apache:apache](https://github.com/apache/maven-apache-parent) from 36 to 37. - [Release notes](https://github.com/apache/maven-apache-parent/releases) - [Commits](https://github.com/apache/maven-apache-parent/commits) --- updated-dependencies: - dependency-name: org.apache:apache dependency-version: '37' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 1 天前
f3fa4751 Signed-off-by: 高春晖 <18220699480@163.com> 3 天前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐