在spring cloud微服务搭建过程中,我们创建了多个model,如图:

在项目完工之后,我需要将项目打包部署到服务器,而每次都是进入相应的模块目录下,分别打包: 

这样做比较麻烦,下面介绍通过父子工程来实现一次性打包项目。

一.修改聚合父工程

打开父项目的pom.xml文件,里面有如下基本信息:

<modelVersion>4.0.0</modelVersion>
<name>springcloud</name>
<groupId>springcloud</groupId>
<artifactId>springcloud</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

添加如下信息,这里是继承springboot提供的父工程,这段信息之前我是配置在子工程里面的,现在配于此处,子工程则不需要配置:

<parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>1.5.10.RELEASE</version>
      <relativePath/> <!-- lookup parent from repository -->
 </parent>

声明多个模块:

<modules>
      <module>eureka_server</module>
      <module>service_quan</module>
      <module>service_feign</module>
      <module>service_zuul</module>
      <module>spring_kafka</module>
 </modules>

统一管理依赖的版本号(可加可不加):

<dependencyManagement>
     <dependencies>
         <dependency>
             <groupId>com.example</groupId>
             <artifactId>eureka_server</artifactId>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>com.example</groupId>
             <artifactId>service_quan</artifactId>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>com.example</groupId>
             <artifactId>service_feign</artifactId>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>com.example</groupId>
             <artifactId>service_zuul</artifactId>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>com.example</groupId>
             <artifactId>spring_kafka</artifactId>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
     </dependencies>
 </dependencyManagement>

二.修改子模块,以eureka_server为例,打开它的pom.xml文件: 
基本信息:

<modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>eureka_server</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>eureka_server</name>
  <description>Demo project for Spring Boot</description>

添加如下,继承项目的父工程:

<parent>
      <groupId>springcloud</groupId>
      <artifactId>springcloud</artifactId>
      <version>1.0-SNAPSHOT</version>
 </parent>

其他依赖相关的东西和以前一样,正常编写,如果你的子工程相关依赖都一样的话,可以通通配置到父工程的pom.xml文件中去,我这里有些许差别,就不配置了。 
最后,需在各个子模块中添加打包插件,这个插件主要是构建可执行的jar:

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

开始打包:

mvn clean package

打包结果如下,则表示成功:

在taget下就会生成一个jar包,这就算大功告成啦~~~

微服务spring cloud 价值分享,技术交流 欢迎入QQ群:863634857,一起讨论微服务

Spring cloud 通过父工程打包多个子工程相关推荐

  1. 微服务理念与Spring Cloud入门-----父工程与API子工程的创建教程

    前言 随着软件工程的规模的迅速扩大,对响应的速度的要求的越来越高,软件的开发过程面临越来越大的挑战.为了提高开发的效率,和质量,以及对成本的压缩,对软件的模块化,以及希望像硬件模块一样,能即插即用,成 ...

  2. SpringCloud - Spring Cloud根/父项目,开发准备(二)

    一.Spring Cloud开发项目工程说明 在后续的 Spring Cloud 工程项目开发,以及博文中,都要注意此文说明! 1.Spring Cloud 本身并不是一个拿来即可用的框架,它是一套微 ...

  3. spring cloud各个微服务打包到docker容器内

    日常你所启动的微服务比如这样的 java -jar eureka-0.0.1-SNAPSHOT.jar --server.port=41578 --spring.profiles.active=loc ...

  4. 熬夜肝了这篇Spring Cloud Gateway的功能及综合使用

    前言 SpringCloud 是微服务中的翘楚,最佳的落地方案. Spring Cloud Gateway 是 Spring Cloud 新推出的网关框架,之前是 Netflix Zuul.网关通常在 ...

  5. 分布式微服务Spring Cloud

    Spring Cloud 微服务概念 版本选择 创建工程 创建父工程 创建子模块 yml配置文件 启动类 创建数据库和表 编写实体类和DAO层 编写业务层和控制层 热部署Devtools 服务间的调用 ...

  6. 《Spring Cloud Netflix官方文档》2. 服务发现:Eureka服务器

    2. 服务发现:Eureka服务器 2.1 如何创建Eureka服务器 引用org.springframework.cloud的spring-cloud-starter-eureka-server就可 ...

  7. Spring Cloud 中文文档

    Spring Cloud 官方文档 Spring Cloud为开发人员提供了用于快速构建分布式系统中某些常见模式的工具(例如,配置管理,服务发现,断路器,智能路由,微代理,控制总线).分布式系统的协调 ...

  8. Spring Cloud项目是如何读取bootstrap.properties文件的?

    提前说明:关于Spring Cloud和Spring Boot源码分析基于的版本如下所示 <!-- Spring Dependencies --> <dependency> & ...

  9. SpringCloud - Spring Cloud Netflix 之 Hystrix熔断器(七)

    阅读本文前可先参考 SpringCloud - Spring Cloud根/父项目,开发准备(二)_MinggeQingchun的博客-CSDN博客 在微服务架构中,一个应用往往由多个服务组成,这些服 ...

最新文章

  1. filezilla 共享多个目录_FileZilla|一个免费开源的FTP软件!
  2. Spring Webflux: Kotlin DSL [片断]
  3. 六、Springmvc json数据交互
  4. 两分钟倒计时(Python)
  5. Windows SharePoint Services To Be Open Source With 2007 Microsoft Office Release
  6. php json_encode 中文乱码解决方法
  7. 电脑如何测网速_【网络调试】网络速度检测工具有哪些?这五款工具让你随时掌控网速...
  8. WinForm与WPF下跨线程调用控件
  9. 安装Vue-DevTools插件及免费分享安装包
  10. PSP-DDR跳舞机模拟器制谱教程
  11. 【HUSTOJ】1055: 字符图形11-字母正三角
  12. git push解决办法: ! [remote rejected] master -> master (pre-receive hook declined)
  13. Chrome插件安装及程序包无效的解决方法
  14. 2021年煤矿瓦斯检查证考试及煤矿瓦斯检查模拟考试题
  15. 九章算法 | 苏州微软面试题:程序检查
  16. 贝赛尔曲线及其应用全面解析
  17. (亲测可用)如何在Win10家庭版中找回组策略编辑器
  18. 流畅的python第二章, 列表和元组和数组
  19. python基础知识集(三)
  20. 41个搜索引擎免费登陆入口大全

热门文章

  1. 翻译: 成长心态 成功的新心理学
  2. 微信支付网络监控工具部署指引
  3. JVM系列五JVM监测工具[整理中(转)
  4. Qt - WPS文本编辑器(WPS段落对齐)
  5. 十八、商城 - 规格管理-模板管理(6)
  6. 新版TCGA数据库学习:批量下载新版TCGA数据
  7. 写一篇产品体验报告需从哪些方面入手?
  8. Win10下安装学习、开发可用的mysql
  9. 防火墙的基础知识(会话表)
  10. Visio镜像翻转图形