• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

使用maven搭建父子工程项目

武飞扬头像
竟未曾年少轻狂
帮助1

创建父子工程,可以通过父工程来引入jar,定义统一的版本号等。更方便对整个项目的jar包实现统一化管理,让项目的层次更加清晰。

一、创建父工程

第一步:file–>new–>project–>maven

默认使用jdk1.8,不引入任何jar包,直接创建空项目,直接点击Next

学新通

第二步:修改默认项目名称、项目路径、包。然后Finish

学新通

第三步:到这里父工程就建好了,在pom.xml设置,项目类型打包方式有pom,war,jar三种。因为是父工程我们设置为pom。

配置<packaging>pom</packaging>的意思是使用maven分模块管理,都会有一个父级项目,pom文件一个重要的属性就是packaging(打包类型),一般来说所有的父级项目的packaging都为pom,packaging默认类型jar类型,如果不做配置,maven会将该项目打成jar包。
学新通

第四步:配置pom.xml

我们使用properties来进行版本号的统一管理,使用dependencyManagement来管理依赖

二、创建子工程

第一步:创建module子工程:在项目根目录右键—>new—>Module

1、使用spring-initializr来创建子工程,可以选择需要的依赖,无需手动导入

2、使用maven直接创建,需要手动导入jar

这里是为了展示父子工程的依赖的关系,我们使用maven选项创建。

学新通
学新通

第二步:声明artifactid

这里我们是不需要来声明groupid的,因为是子工程,所以这个值是固定的,我们可以自定义artifactid

学新通

第三步:依次创建api、framework、system模块

三、引入依赖、统一jar版本

  1.  
    <properties>
  2.  
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  3.  
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  4.  
    <java.version>1.8</java.version>
  5.  
    <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
  6.  
    <druid.version>1.2.15</druid.version>
  7.  
    <bitwalker.version>1.21</bitwalker.version>
  8.  
    <swagger.version>3.0.0</swagger.version>
  9.  
    <kaptcha.version>2.3.3</kaptcha.version>
  10.  
    <pagehelper.boot.version>1.4.6</pagehelper.boot.version>
  11.  
    <fastjson.version>2.0.23</fastjson.version>
  12.  
    <oshi.version>6.4.0</oshi.version>
  13.  
    <commons.io.version>2.11.0</commons.io.version>
  14.  
    <commons.fileupload.version>1.4</commons.fileupload.version>
  15.  
    <commons.collections.version>3.2.2</commons.collections.version>
  16.  
    <poi.version>4.1.2</poi.version>
  17.  
    <velocity.version>2.3</velocity.version>
  18.  
    <jwt.version>0.9.1</jwt.version>
  19.  
    </properties>
  20.  
     
  21.  
    <!-- 依赖声明 -->
  22.  
    <dependencyManagement>
  23.  
    <dependencies>
  24.  
    <!-- SpringBoot的依赖配置-->
  25.  
    <dependency>
  26.  
    <groupId>org.springframework.boot</groupId>
  27.  
    <artifactId>spring-boot-dependencies</artifactId>
  28.  
    <version>2.5.14</version>
  29.  
    <type>pom</type>
  30.  
    <scope>import</scope>
  31.  
    </dependency>
  32.  
     
  33.  
    <!-- 阿里数据库连接池 -->
  34.  
    <dependency>
  35.  
    <groupId>com.alibaba</groupId>
  36.  
    <artifactId>druid-spring-boot-starter</artifactId>
  37.  
    <version>${druid.version}</version>
  38.  
    </dependency>
  39.  
     
  40.  
    <!-- 解析客户端操作系统、浏览器等 -->
  41.  
    <dependency>
  42.  
    <groupId>eu.bitwalker</groupId>
  43.  
    <artifactId>UserAgentUtils</artifactId>
  44.  
    <version>${bitwalker.version}</version>
  45.  
    </dependency>
  46.  
     
  47.  
    <!-- pagehelper 分页插件 -->
  48.  
    <dependency>
  49.  
    <groupId>com.github.pagehelper</groupId>
  50.  
    <artifactId>pagehelper-spring-boot-starter</artifactId>
  51.  
    <version>${pagehelper.boot.version}</version>
  52.  
    </dependency>
  53.  
     
  54.  
    <!-- 获取系统信息 -->
  55.  
    <dependency>
  56.  
    <groupId>com.github.oshi</groupId>
  57.  
    <artifactId>oshi-core</artifactId>
  58.  
    <version>${oshi.version}</version>
  59.  
    </dependency>
  60.  
     
  61.  
    <!-- Swagger3依赖 -->
  62.  
    <dependency>
  63.  
    <groupId>io.springfox</groupId>
  64.  
    <artifactId>springfox-boot-starter</artifactId>
  65.  
    <version>${swagger.version}</version>
  66.  
    <exclusions>
  67.  
    <exclusion>
  68.  
    <groupId>io.swagger</groupId>
  69.  
    <artifactId>swagger-models</artifactId>
  70.  
    </exclusion>
  71.  
    </exclusions>
  72.  
    </dependency>
  73.  
     
  74.  
    <!-- io常用工具类 -->
  75.  
    <dependency>
  76.  
    <groupId>commons-io</groupId>
  77.  
    <artifactId>commons-io</artifactId>
  78.  
    <version>${commons.io.version}</version>
  79.  
    </dependency>
  80.  
     
  81.  
    <!-- 文件上传工具类 -->
  82.  
    <dependency>
  83.  
    <groupId>commons-fileupload</groupId>
  84.  
    <artifactId>commons-fileupload</artifactId>
  85.  
    <version>${commons.fileupload.version}</version>
  86.  
    </dependency>
  87.  
     
  88.  
    <!-- excel工具 -->
  89.  
    <dependency>
  90.  
    <groupId>org.apache.poi</groupId>
  91.  
    <artifactId>poi-ooxml</artifactId>
  92.  
    <version>${poi.version}</version>
  93.  
    </dependency>
  94.  
     
  95.  
    <!-- velocity代码生成使用模板 -->
  96.  
    <dependency>
  97.  
    <groupId>org.apache.velocity</groupId>
  98.  
    <artifactId>velocity-engine-core</artifactId>
  99.  
    <version>${velocity.version}</version>
  100.  
    </dependency>
  101.  
     
  102.  
    <!-- collections工具类 -->
  103.  
    <dependency>
  104.  
    <groupId>commons-collections</groupId>
  105.  
    <artifactId>commons-collections</artifactId>
  106.  
    <version>${commons.collections.version}</version>
  107.  
    </dependency>
  108.  
     
  109.  
    <!-- 阿里JSON解析器 -->
  110.  
    <dependency>
  111.  
    <groupId>com.alibaba.fastjson2</groupId>
  112.  
    <artifactId>fastjson2</artifactId>
  113.  
    <version>${fastjson.version}</version>
  114.  
    </dependency>
  115.  
     
  116.  
    <!-- Token生成与解析-->
  117.  
    <dependency>
  118.  
    <groupId>io.jsonwebtoken</groupId>
  119.  
    <artifactId>jjwt</artifactId>
  120.  
    <version>${jwt.version}</version>
  121.  
    </dependency>
  122.  
     
  123.  
    <!-- 验证码 -->
  124.  
    <dependency>
  125.  
    <groupId>pro.fessional</groupId>
  126.  
    <artifactId>kaptcha</artifactId>
  127.  
    <version>${kaptcha.version}</version>
  128.  
    </dependency>
  129.  
    </dependencies>
  130.  
    </dependencyManagement>

四、关联父子模块

点击maven,在父工程下install初始化一下,这时父子工程才能关联。

学新通

注意点:

1.父工程的pom.xml文件的打包方式应该为pom

2.想要子工程的依赖指向父工程的话,父工程的依赖应该使用dependencyManagement来管理。

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfhiich
系列文章
更多 icon
同类精品
更多 icon
继续加载