springboot工程maven打包时,如果有依赖工程总是报找不到,解决办法

最近公司使用springboot开发项目,使用的构建工具是maven,项目分了很多模块,并且模块之间还存在一定的依赖,比如说一个项目common是提供各项目通用的工具类,公共的类等

11464886-201ed0c8ad737ae0.png

当对工程执行:mvn clean package 就会包依赖 pyyadmin-common-xxxx.jar 和 pyyadmin-common-model.xxxx.jar 找不到

而此时你可能会去将 pyyadmin-commonpyyadmin-common-model 执行 mvn clean package,此时会报如下错误:

[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.208 s
[INFO] Finished at: 2019-11-19T10:45:57+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.7.RELEASE:repackage (repackage) on project pyyadmin-common: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.7.RELEASE:repackage failed: Unable to find main class -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

注意!注意!这里有一个巨坑,我已经义无反顾的跳进去一次了,大家一定不要再往里面跳了:common打包出来的应该是不可执行的jar包,所以不要在Common的pom中定义spring-boot-maven-plugin插件,因为这个SpringBoot插件会在Maven的package后进行二次打包,目的为了生成可执行jar包,如果common中定义了这个插件,会报错提示没有找到main函数。

问题就出现在这里:切记,普通模块工程中一定要记得去掉下面 maven编译插件

<build>
        <plugins>
            <!-- maven 编译插件 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值