IDEA打包基于多层Maven构建的多module springboot项目-----基于尚医通的基本部署

1. 项目架构

demo--最外层的父工程--Maven工程
common---Maven工程:
          common下创建两个模块存放工具类(common-util、service-util)
hospital-manage-----单独的SpringBoot工程
model:工具类
service-----Maven工程:
          service-cmn3:基于Maven引入的module,有SpringBoot启动类
          service-hospital:基于Maven引入的module,有SpringBoot启动类
          service-user:基于Maven引入的module,有SpringBoot启动类
service_client-----Maven工程:
         service_client_server:公共类,无启动类

PS:
一般工具类module下不含有SpringBoot启动类–(如common-util、service-util、model、service_client_server)
但是有时候也会报错:打包时出现unable to find the main class
解决方法请看下面的补充一
在这里插入图片描述

2. pom文件的配置

参考链接:
https://www.freesion.com/article/8212834032/

这部分的配置很关键,折腾了很久才配置成功的

步骤一

最外层demo的pom.xml配置信息:
父模块都是pom打包方式(packaging为pom)
common 、service、service_client属于第二层级父模块,也是采用pom打包
(由于其下依旧有子模块,所以依然是pom的打包方式,同时要声明它的父模块是谁)
demo 的pom:
在这里插入图片描述
common 的pom
在这里插入图片描述
service的pom

在这里插入图片描述
service_client的pom
在这里插入图片描述

步骤二

(1)

在最外层的父模块(demo模块)的pom.xml文件最下面加上:
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

    <resources>
        <!-- 项目编译打包时将java目录中的*.xml文件进行打包,默认是不进行打包的 -->
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>  <!-- 两个 **  表示多级目录,一个 * 表示只有一级目录-->
            </includes>
            <filtering>false</filtering>
        </resource>

        <!-- 项目编译打包时将resource目录中的配置文件进行打包,默认是不进行打包的 -->
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.tld</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        
    </resources>

</build>

注释:<plugins>中配置的是springboot的maven插件,后面的<executions>在最外层的父模块中定义,具体原因未知。
	下面的<resources>都是编译打包的时候需要用到,具体原因已经写在注解中。

(2)

在common-util、service-util、model、service_client_server
PS:工具类模块下都要添加

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

如下
在这里插入图片描述
在这里插入图片描述

其他几个模块就不截图了

(3)
切记:在工具类模块下千万不要声明打包方式,否则会报错
在这里插入图片描述
(4)
切记:在SpringBoot工程模块下也千万不要声明打包方式,否则会报错
hospital-manage-----单独的SpringBoot工程
service-cmn3:基于Maven引入的module,有SpringBoot启动类
service-hospital:基于Maven引入的module,有SpringBoot启动类
service-user:基于Maven引入的module,有SpringBoot启动类
在这里插入图片描述

3.打包

—右侧的maven工具栏,
—最外层模块(demo)
—点击Lifecycle,—点击clean,----再点击package
在这里插入图片描述
打包成功:
在这里插入图片描述
在这里插入图片描述

4 部署

到打包生成jar包人文件夹下,采用cmd的方式一个个的启动SpringBoot的jar包
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
PS:其他工具类的模块所打包称为的jar包是不需要启动的
启动命令:java -jar xxx.jar
在这里插入图片描述

重新打包

  1. 若修改完配置,需要重新打包
    在这里插入图片描述
  2. 对于单独创建的SpringBoot工程需要再次重新打包–如:hospital-manage
    在这里插入图片描述
  3. 因为可以看出demo的package不包括单独创建的SpringBoot项目hospital-manage
    在这里插入图片描述

补充

补充一:
工具类模块打包时出现unable to find the main class
在对应的模块下加入一个空的启动类就不会再报错了

在这里插入图片描述
如下所示
在这里插入图片描述

补充二:
在打包之后,重新启动idea里面的SpringBoot工程时,出现springboot启动错误: 找不到或无法加载主类

解决方法:

到具体的SpringBoot工程下
mvn clean compile
mvn install
再重启该SpringBoot工程
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值