Springboot mavne项目多模块打包,报错 找不到 base包,找不到common类等等

 

报错示例:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.4.RELEASE:repackage (default) on project jcdemo-common: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.4.RELEASE:repackage failed: Unable to find main class -> [Help 1]

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

 

认真看maven打包报错里面提到的关键信息:

repackage (default) on project jcdemo-common

 unable to find main class

这是因为什么? 是因为我的jcdemo-common 这个模块是个没有main函数入口的模块,只是用于提供jar依赖给其他的模块使用。

 

目前我的项目结构为:

 

jcdemo-parent   这个是父模块

jcdemo-common 这个是基础的公共类模块

jcdemo-myWebA 这是一个web A项目,打包设置是war ,里面引用了common的jar

jcdemo-myWebB 这是一个web B项目,打包设置是war ,里面也引用了common的jar

 

之所以出现上面找不到 jcdemo-common模块的类,是因为我在  jcdemo-parent 和   jcdemo-common 的pom.xml里面都加入了(不要加!):

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

那么仅仅是因为这个原因吗? 直接看正确流程:

 

maven多模块打包 正规流程

第一步:

首先,在父模块的pom.xml  ,排查是否加了 :

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

如果有,删掉。

 

第二步:

 

检测所谓的 common 模块的pom.xml,排查是否也加了:

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

如果有,也删掉,因为我们的common 模块是没有main函数入口的。

然后在common 模块的pom.xml里加上:

    <build>
        <plugins>
            <!-- 资源文件拷贝插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

第三步,在你的web模块的pom.xml里面,加上:


        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <mainClass>com.xxx.Application</mainClass>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

注意指明打包的main函数入口,也就是 springboot的启动类:

 

 

ok,可以打包了(直接对着你的父模块点package就行,也可以先clean一下):

可以看到,该打的都成功打包:

 

  • 9
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小目标青年

对你有帮助的话,谢谢你的打赏。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值