Unable to find a single main class from the following candidates 问题解决

背景

maven父子工程间引用打包,产生的异常

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.12.RELEASE:repackage (repackage) on project shop-common: Execution repackage of goal org.springfr
amework.boot:spring-boot-maven-plugin:2.1.12.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.huanchuang.common.util.CommonAlgoUtil,
com.huanchuang.common.util.DateUtils, com.huanchuang.common.service.impl.MdSensorServiceImpl] -> [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
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :shop-common

 解决

那如何解决呢

1.父子工程引用 

多模块依赖时,如果类似common之类的module只作为依赖包,而无需作为springboot的application时,以下打包插件不应配置到顶级pom及common的pom中

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

2.单一工程

在pom.xml文件中加入主类,用于指定加载的主类(用于告诉spring boot maven plugin哪个类是入口类即可)

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>com.huanchuang.commmon.Application</mainClass>
    </configuration>
</plugin>

PS: 其中在打包的时候resources文件下所有的目录都会自动被打包,如果是没有加载上去,可以按照下面的方式指定静态文件

<resources>
    <resource>
        <directory>src/main</directory>
            <includes>
                <include>**/*.properties</include>
            </includes>
            <filtering>false</filtering>
     </resource>
</resources>

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值