多模块项目微服务器,springboot多模块项目(微服务项目)正确打包(jar)方式...
大致步骤
新建一个springboot项目名称为父亲
添加父快捷方式。新建子模块,子模块同时插入新建springboot的项目,依次创建enty和web模块(关键是并配置好pom文件)
web模块依赖于entiy模块中的实体类,创建测试控制器,先测试项目没问题再开始打包(jar)
开始打包
测试jar是否有用
创建项目
注意点 :子模块需要保留xx.iml,xx.mvn文件,父模块保留.idea,.mvn文件 。如果删除了这些可能会报发现主类的错误
要打包项目大致的目录结构如下 :
第一级别:father
第二级别:service、web、entiy
第三级别:eduService
其中web、eduService是web项目可以独立运行,且依赖entiy( 学会了这个,以后所有的多模块项目都能学会打包(jar))
配置父亲的pom文件
配置父模块注意点一: 修改打包为pom(一般父级的打包方式为pom,所以father、service的打包方式为pom)。
pompackaging>
配置父模块注意点二: 记得指定该父模块下面有哪些子模块
entiymodule>
webmodule>
servicemodule>
modules>
配置父模块注意点三: 记得指定java的版本号
1.8java.version>
properties>
配置父模块注意点四: 只需在father配置apache的maven打包插件,service的其他父模块不需要配置这个
org.apache.maven.pluginsgroupId>
maven-compiler-pluginartifactId>
3.1version>
${java.version}source>
${java.version}target>
configuration>
plugin>
org.apache.maven.pluginsgroupId>
maven-surefire-pluginartifactId>
2.19.1version>
trueskipTests>
configuration>
plugin>
plugins>
build>
完整father的pom文件如下:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0modelVersion>
org.springframework.bootgroupId>
spring-boot-starter-parentartifactId>
2.4.0version>
parent>
entiymodule>
webmodule>
servicemodule>
modules>
com.zzhgroupId>
fatherartifactId>
0.0.1-SNAPSHOTversion>
pompackaging>
fathername>
1.8java.version>
properties>
org.springframework.bootgroupId>
spring-boot-starterartifactId>
dependency>
org.springframework.bootgroupId>
spring-boot-starter-testartifactId>
testscope>
dependency>
dependencies>
org.apache.maven.pluginsgroupId>
maven-compiler-pluginartifactId>
3.1version>
${java.version}source>
${java.version}target>
configuration>
plugin>
org.apache.maven.pluginsgroupId>
maven-surefire-pluginartifactId>
2.19.1version>
trueskipTests>
configuration>
plugin>
plugins>
build>
project>
配置子模块的pom文件
配置子模块注意点一 : 在parent节点下面加上relativePath,作用是指明依赖哪个父模块pom文件(如果是依赖直接父级就是…/规则和写html那种引用绝对路径一样)。
../pom.xmlrelativePath>
配置子模块注意点二 : 修改打包方式为jar
jarpackaging>
配置子模块注意点三 : 加上springBoot的maven打包插件,并且指定运行的主入口类(springboot的maven插件,用这个插件打包的Jar包可以直接运行,但是不可依赖!),如果此子模块需要被依赖,那么还需加上这句代码(不加会报找不到类的错误)。(entiy模块需要加,其他子模块不要加)
感谢大佬的文章
execclassifier>
org.springframework.bootgroupId>
spring-boot-maven-pluginartifactId>
execclassifier>
com.zzh.demo.EntiyApplicationmainClass>
ZIPlayout>
configuration>
repackagegoal>
goals>
execution>
executions>
plugin>
plugins>
build>
配置子模块注意点四 : 指定以下bulid的编码规则
UTF-8project.build.sourceEncoding>
UTF-8project.reporting.outputEncoding>
1.8java.version>
properties>
完整的web模块pom文件
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0modelVersion>
org.springframework.bootgroupId>
spring-boot-starter-parentartifactId>
2.4.0version>
../pom.xmlrelativePath>
parent>
com.zzhgroupId>
webartifactId>
0.0.1-SNAPSHOTversion>
webname>
jarpackaging>
UTF-8project.build.sourceEncoding>
UTF-8project.reporting.outputEncoding>
1.8java.version>
properties>
com.zzhgroupId>
entiyartifactId>
0.0.1-SNAPSHOTversion>
dependency>
org.springframework.bootgroupId>
spring-boot-starter-webartifactId>
dependency>
org.springframework.bootgroupId>
spring-boot-starter-testartifactId>
testscope>
dependency>
dependencies>
org.springframework.bootgroupId>
spring-boot-maven-pluginartifactId>
com.zzh.demo.WebApplicationmainClass>
ZIPlayout>
configuration>
repackagegoal>
goals>
execution>
executions>
plugin>
plugins>
build>
project>
完整的eduService模块pom文件(由于service中配置了springboot的打包插件,由于可以依赖传递,这里可以不用配置打包插件)
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
serviceartifactId>
com.zzhgroupId>
0.0.1-SNAPSHOTversion>
../pom.xmlrelativePath>
parent>
4.0.0modelVersion>
eduServiceartifactId>
jarpackaging>
eduServicename>
UTF-8project.build.sourceEncoding>
UTF-8project.reporting.outputEncoding>
1.8java.version>
properties>
project>
编写测试代码
entiy模块
编写entiyTest类,并且自己调用自己的entiyTest
public class entiyTest {
public void showEntiyTest() {
System.out.println("调用showEntiyTest成功!!");
}
}
@RestController
@RequestMapping("/entiy")
public class entiyController {
@RequestMapping("/test")
public String testEntiy() {
System.out.println("entiySucess");
return "entiySucess";
}
}
web模块(前提:我们引入了entiy模块的)
@RestController
@RequestMapping("/web")
public class controller {
@RequestMapping("/test")
public String testWeb() {
entiyTest entiyTest = new entiyTest();
entiyTest.showEntiyTest();
return "webSucess";
}
}
eduService模块(前提:我们引入了entiy模块的)
@RestController
@RequestMapping("/eduService")
public class controller {
@RequestMapping("/test")
public String testWeb() {
entiyTest entiyTest = new entiyTest();
entiyTest.showEntiyTest();
return "eduService";
}
}
终极打包了
直接点clean接着点package或者install一键打包就ok了?
然后你会发现你会报这个错哈哈哈哈哈哈
解决办法,点一下这个在clean、package(maven的编译打包检查:关闭点一下就可以了,忽略检查测试文件)
可以参考这个文章
这下就真的打包成功啦开心吧哈哈哈。输入java -jar 然后按tab键就可以切换jar包名字
全部启动okk了,注意启动entiy模块的这个jar包,这个才是可执行的jar包另外一个是可依赖的jar包
在需要对外提供依赖的项目的pom里设置(如本项目的xxx-a、xxx-b),这样设置会让项目生成两个jar:一个可执行jar,一个可依赖的jar;
org.springframework.bootgroupId>
spring-boot-maven-pluginartifactId>
execclassifier>
configuration>
plugin>
plugins>
build>
项目源码链接,点个start吧老妹们哈哈哈哈
多模块项目微服务器,springboot多模块项目(微服务项目)正确打包(jar)方式...相关推荐
- 【微服务器集群】做毕设收尾阶段,如何创建微服务器集群来跑自己的项目?
最近在做毕设,即将收尾阶段,有很多小伙伴在后台问我,毕设项目写完了,很想把项目放到服务器上跑,怎么搞?其实这个并不难,很好弄,你只需要了解一以下三点,你就OK了哟! (文章写的一般,可能有不专业的地方 ...
- JAVA Cloud微服务项目实战课程 SpringBoot 2.x +SpringCloud 微服务课程
课程目录 第1章 课程介绍 课程导学和学习建议 1-1 SpringCloud导学 1-2 获取源码说明 1-3 提问建议 1-4 点餐项目演示说明 第2章 微服务介绍 什么是微服务, 单体架构优缺点 ...
- 超微服务器修改raid卡,超微主板怎么创建RAID磁盘阵列 AMD主板RAID设置介绍
原标题:"超微主板怎么创建RAID磁盘阵列 服务器组建RAID0.RAID1图文教程"的相关电脑教程资料分享. - 来源:191路由网 - 编辑:小机. 一般服务器会配备两个或者多 ...
- 超微服务器怎么开虚拟化,超微6016TT-IBXF服务器Supermicro开启虚拟化支持
玩虚拟机必须要先使能Intel Virtualization.Intel的虚拟化技术主要有两个方面:一个是CPU的VT-x,一个是主板的VT-d.按照简单的理解,VT-x使得CPU的指令集支持虚拟化, ...
- gitlab-ci docker maven 自动化流水线部署 springboot多模块项目
一.准备 首先 需要两台服务器(这里为了下面方便理解,我们约定这两台服务器地址.名称和系统) 1.gitlab 服务器 服务器A(地址10.10.10.7)(内存大于4g不然会一直死)( CentOS ...
- nodeJS+express+mysql模块封装之服务器渲染小demo
nodeJS+express+mysql模块封装之服务器渲染小demo 创建一个小项目 npm init 下载相关中间件(根据package.js来下载) package.js 目录结构 index. ...
- 超微服务器做系统,超微服务器做系统
超微服务器做系统 内容精选 换一换 客户软件在基于鲲鹏的服务器上运行遇到性能问题时,可用系统性能分析来快速分析和定位.系统性能分析工具将采集系统如下数据:系统软硬件配置和运行信息,例如:CPU类型.内 ...
- 基于 Springboot 的 Bark 通知辅助处理项目
基于 Springboot 的 Bark 通知辅助处理项目 1 系统介绍 1.1 系统组成 2 技术说明 2.1 系统项目介绍 2.2 使用场景 2.2 系统网络架构图 2.4 系统处理流程图 3 系 ...
- 内置在maven项目的服务器,IDEA使用maven中tomcat插件来启动服务器配置
一 .在项目pom文件中配置tomcat 先添加如下配置: org.apache.maven.plugins maven-compiler-plugin 2.3.2 1.7 1.7 org.apach ...
最新文章
- 拟南芥arabidopsis 全染色体
- 360 自动打开word_EXCEL的数据和图表如何与ppt,Word关联,看完你就会了
- linux c 运行报错 killed
- P1628 合并序列
- Python有多火,来看一份24小时榜单,从入门到进阶
- 亚马逊涨了 $4 千亿?!为什么它能成为疫情中获益最大的公司
- 信息学奥赛一本通(1260:【例9.4】拦截导弹(Noip1999))
- 【FFMPEG系列】FFMPEG linux下集成x264
- dokuwiki语法
- 计算机检索系统中 每一种文献特征,自考《档案文献检索》串讲资料(1)
- 银河麒麟系统安装字体
- keil5怎么放大字体_keil4调节字体 keil字体放大快捷键
- 医疗器械质量管理体系 - ISO 13485 简介
- 用excel打开txt文件
- 2021年全球及中国AMOLED行业发展现状、竞争格局及未来发展趋势分析,柔性AMOLED面板将占领市场「图」
- windows中的文件共享(SMB服务)
- 隔离:正向隔离、反向隔离。
- 甲骨文服务器操作系统,甲骨文年内完成操作系统移换 Linux将成主要平台
- spss python_ARIMA模型 - [SPSS Python]
- kindle for pc版本更新后无法打开解决办法