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
解决方法请看下面的补充一
参考链接:
https://www.freesion.com/article/8212834032/
这部分的配置很关键,折腾了很久才配置成功的
最外层demo的pom.xml配置信息:
父模块都是pom打包方式(packaging为pom)
common 、service、service_client属于第二层级父模块,也是采用pom打包
(由于其下依旧有子模块,所以依然是pom的打包方式,同时要声明它的父模块是谁)
demo 的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)
切记:在工具类模块下千万不要声明打包方式,否则会报错
—右侧的maven工具栏,
—最外层模块(demo)
—点击Lifecycle,—点击clean,----再点击package
打包成功:
到打包生成jar包人文件夹下,采用cmd的方式一个个的启动SpringBoot的jar包
PS:其他工具类的模块所打包称为的jar包是不需要启动的
启动命令:java -jar xxx.jar
补充一:
工具类模块打包时出现unable to find the main class
在对应的模块下加入一个空的启动类就不会再报错了
如下所示
补充二:
在打包之后,重新启动idea里面的SpringBoot工程时,出现springboot启动错误: 找不到或无法加载主类
解决方法:
到具体的SpringBoot工程下
mvn clean compile
mvn install
再重启该SpringBoot工程
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- awee.cn 版权所有 湘ICP备2023022495号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务