雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

Java

當(dāng)前位置:主頁 > 軟件編程 > Java >

Idea創(chuàng)建多模塊maven聚合項(xiàng)目的實(shí)現(xiàn)

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:Java|點(diǎn)擊:

1.怎么理解maven的繼承和聚合

maven多模塊項(xiàng)目通常由一個(gè)父模塊和若干個(gè)子模塊構(gòu)成,每個(gè)模塊都對(duì)應(yīng)著一個(gè)pom.xml。它們之間通過繼承和聚合(也稱作多模塊)相互關(guān)聯(lián)。多模塊適用于一些比較大的項(xiàng)目,通過合理的模塊拆分,實(shí)現(xiàn)代碼的復(fù)用,便于維護(hù)和管理。
繼承:和java中的繼承有點(diǎn)類似,就是父pom.xml聲明的版本和引用的jar,子模塊可以不用再引用直接調(diào)用。
聚合:父模塊包含多個(gè)子模塊就是聚合,多個(gè)子模塊之間可以調(diào)用,但是要注意關(guān)系,不要兩個(gè)互相依賴,這樣做的好處就是可以通過一條命令進(jìn)行構(gòu)建

注意:

groupId是項(xiàng)目組織唯一的標(biāo)識(shí)符,實(shí)際對(duì)應(yīng)JAVA的包的結(jié)構(gòu),artifactId是項(xiàng)目的唯一的標(biāo)識(shí)符,實(shí)際對(duì)應(yīng)項(xiàng)目的名稱,就是項(xiàng)目根目錄的名稱。groupId一般分為多個(gè)段,一般第一段為域,第二段為公司名稱,第三段通常為項(xiàng)目名稱。

2.Idea創(chuàng)建多模塊項(xiàng)目

2.1創(chuàng)建父模塊(空的maven項(xiàng)目)




pom.xml配置
<modelVersion>4.0.0</modelVersion> 
<parent> 
 <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-parent</artifactId> 
 <version>2.1.6.RELEASE</version> 
</parent> 
 
<groupId>cn.yskcoder.fire</groupId> 
<artifactId>fire</artifactId> 
<packaging>pom</packaging> 
<version>v1.0</version> 
 
 
<modules> 
 <module>fire-common</module> 
 <module>fire-dao</module> 
 <module>fire-service</module> 
 <module>fire-web</module> 
</modules> 
 
<properties> 
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
 <java.version>1.8</java.version> 
 <spring-boot.version>2.1.6.RELEASE</spring-boot.version> 
 
</properties>

2.2.創(chuàng)建工具類(common)模塊(dao、service同這個(gè)操作一樣)



pom.xml配置
<modelVersion>4.0.0</modelVersion> 
<parent> 
 <artifactId>fire</artifactId> 
 <groupId>cn.yskcoder.fire</groupId> 
 <version>v1.0</version> 
</parent> 
 
<!--模塊信息--> 
<packaging>jar</packaging> 
<name>fire-common</name> 
<artifactId>fire-common</artifactId> 
<description>fire 通用工具類模塊</description> 
 
<!--模塊依賴--> 
<dependencies> 
 
</dependencies>

2.3.創(chuàng)建數(shù)據(jù)庫訪問(dao)模塊(只貼pom.xml代碼)

<modelVersion>4.0.0</modelVersion> 
<parent> 
 <artifactId>fire</artifactId> 
 <groupId>cn.yskcoder.fire</groupId> 
 <version>v1.0</version> 
</parent> 
 
<!--模塊信息--> 
<packaging>war</packaging> 
<name>fire-web</name> 
<artifactId>fire-web</artifactId> 
<description>fire web模塊</description> 
 
<!--模塊依賴--> 
<dependencies> 
 <dependency> <groupId>cn.yskcoder.fire</groupId> 
 <artifactId>fire-service</artifactId> 
 <version>v1.0</version> 
 </dependency> 
 <dependency> <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-web</artifactId> 
 </dependency> 
 <dependency> <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-aop</artifactId> 
 </dependency> 
 <dependency> <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-test</artifactId> 
 <scope>test</scope> 
 </dependency> 
</dependencies>


<build> 
 <plugins> 
  <plugin> 
   <groupId>org.apache.maven.plugins</groupId> 
   <artifactId>maven-compiler-plugin</artifactId> 
   <version>3.1</version> 
   <configuration> 
    <source>${java.version}</source> 
    <target>${java.version}</target> 
   </configuration> 
  </plugin>
 </plugins>
 <resources> 
  <resource> 
  <directory>src/main/webapp</directory> 
  <filtering>false</filtering> 
  </resource> 
  <resource> 
   <directory>src/main/resources</directory> 
   <filtering>true</filtering> 
  </resource> 
 </resources>
</build>

3.Idea打包多模塊項(xiàng)目

clean package -Dmaven.test.skip=true

接下來有空會(huì)繼續(xù)更新這個(gè)項(xiàng)目
https://github.com/yskcoder/Fire

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:java實(shí)體對(duì)象與Map之間的轉(zhuǎn)換工具類代碼實(shí)例

欄    目:Java

下一篇:SpringCloud融入Python的實(shí)現(xiàn)

本文標(biāo)題:Idea創(chuàng)建多模塊maven聚合項(xiàng)目的實(shí)現(xiàn)

本文地址:http://www.jygsgssxh.com/a1/Java/8869.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有