日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

【sprinb-boot】maven 多模块项目:单独 spring-boot:run 某个模块

發(fā)布時(shí)間:2024/9/19 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【sprinb-boot】maven 多模块项目:单独 spring-boot:run 某个模块 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

目錄

  • 前言
  • 假設(shè)的 maven 多模塊項(xiàng)目
    • 模塊關(guān)系1
    • 模塊關(guān)系2
    • 模塊關(guān)系3
    • 模塊關(guān)系4
  • 示例:模塊關(guān)系1
    • 1,my-parent1/pom.xml 文件
    • 2,my-parent1/my-app1/pom.xml 文件
    • 3,執(zhí)行 mvn spring-boot:run
  • 示例:模塊關(guān)系2
    • 1,my-parent2/pom.xml 文件
    • 2,my-parent2/my-app2/pom.xml 文件
    • 3,執(zhí)行 mvn spring-boot:run
  • 示例:模塊關(guān)系3
    • 1,my-parent3/pom.xml 文件
    • 2,my-parent3/my-app3/pom.xml 文件
    • 3,執(zhí)行 mvn spring-boot:run
  • 示例:模塊關(guān)系4
    • 1,my-parent4/pom.xml 文件
    • 2,my-parent4/my-app4/pom.xml 文件
    • 3,執(zhí)行 mvn spring-boot:run
  • 參考

前言

  • springboot 2.0.0.RELEASE
  • maven 3.5.0
  • maven 多模塊項(xiàng)目關(guān)系

經(jīng)過一段時(shí)間的驗(yàn)證,發(fā)現(xiàn)有不妥之處,再次編輯修正。

假設(shè)的 maven 多模塊項(xiàng)目

假設(shè)多模塊項(xiàng)目的目錄結(jié)構(gòu)如下:

my-parent ├─ my-domain ├─ my-service └─ my-app

該項(xiàng)目可能具備以下集中關(guān)系。

模塊關(guān)系1

同時(shí)具備繼承關(guān)系和聚合關(guān)系。

my-parent1 <<< 無父項(xiàng)目 ├─ my-domain ├─ my-service └─ my-app1 <<< 父項(xiàng)目為 my-parent 的 Spring Boot project

模塊關(guān)系2

僅具備聚合關(guān)系,不具備繼承關(guān)系。

my-parent2 <<< 無父項(xiàng)目 ├─ my-domain ├─ my-service └─ my-app2 <<< 父項(xiàng)目為 spring-boot-starter-parent 的 Spring Boot project

模塊關(guān)系3

同時(shí)具備繼承關(guān)系和聚合關(guān)系。

my-parent3 <<< 父項(xiàng)目為 spring-boot-starter-parent ├─ my-domain ├─ my-service └─ my-app3 <<< 父項(xiàng)目為 my-parent 的 Spring Boot project

模塊關(guān)系4

僅具備聚合關(guān)系,不具備繼承關(guān)系。

my-parent4 <<< 父項(xiàng)目為 spring-boot-starter-parent ├─ my-domain ├─ my-service └─ my-app4 <<< 父項(xiàng)目為 spring-boot-starter-parent 的 Spring Boot project

該如何在my-app上執(zhí)行mvn spring-boot:run?

示例:模塊關(guān)系1

1,my-parent1/pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>test</groupId><artifactId>my-parent1</artifactId><version>1.0</version><packaging>pom</packaging><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><maven-compiler-plugin.version>3.1</maven-compiler-plugin.version></properties><modules><module>my-app1</module></modules><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><source>${java.version}</source><target>${java.version}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins></build> </project>

2,my-parent1/my-app1/pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>test</groupId><artifactId>my-parent1</artifactId><version>1.0</version></parent><artifactId>my-app1</artifactId><properties></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.0.0.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
  • 與其它集中關(guān)系相比,這里多了個(gè) dependencyManagement 。

3,執(zhí)行 mvn spring-boot:run

在my-parent1目錄執(zhí)行如下命令:

shell> mvn spring-boot:run -pl my-app1

或者:

shell> mvn spring-boot:run -pl test:my-app1
  • test 是 groupId
  • my-app1 是 artifactId

示例:模塊關(guān)系2

1,my-parent2/pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>test</groupId><artifactId>my-parent2</artifactId><version>1.0</version><packaging>pom</packaging><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><maven-compiler-plugin.version>3.1</maven-compiler-plugin.version></properties><modules><module>my-app2</module></modules><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><source>${java.version}</source><target>${java.version}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins></build></project>

2,my-parent2/my-app2/pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.0.RELEASE</version><relativePath /> <!-- lookup parent from repository --></parent><groupId>test</groupId><artifactId>my-app2</artifactId><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency></dependencies><build></build></project>

3,執(zhí)行 mvn spring-boot:run

在my-parent1目錄執(zhí)行如下命令:

shell> mvn spring-boot:run -pl my-app2

或者:

shell> mvn spring-boot:run -pl test:my-app2
  • test 是 groupId
  • my-app2 是 artifactId

示例:模塊關(guān)系3

1,my-parent3/pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.0.RELEASE</version><relativePath /> <!-- lookup parent from repository --></parent><groupId>test</groupId><artifactId>my-parent3</artifactId><version>1.0</version><packaging>pom</packaging><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><maven-compiler-plugin.version>3.1</maven-compiler-plugin.version></properties><modules><module>my-app3</module></modules><build></build></project>

2,my-parent3/my-app3/pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>test</groupId><artifactId>my-parent3</artifactId><version>1.0</version></parent><artifactId>my-app3</artifactId><properties></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency></dependencies><build></build></project>

3,執(zhí)行 mvn spring-boot:run

在my-parent1目錄執(zhí)行如下命令:

shell> mvn spring-boot:run -pl my-app3

或者:

shell> mvn spring-boot:run -pl test:my-app3
  • test 是 groupId
  • my-app3 是 artifactId

示例:模塊關(guān)系4

1,my-parent4/pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.0.RELEASE</version><relativePath /> <!-- lookup parent from repository --></parent><groupId>test</groupId><artifactId>my-parent4</artifactId><version>1.0</version><packaging>pom</packaging><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><modules><module>my-app4</module></modules><build></build></project>

2,my-parent4/my-app4/pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.0.RELEASE</version><relativePath /> <!-- lookup parent from repository --></parent><groupId>test</groupId><artifactId>my-app4</artifactId><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency></dependencies><build></build> </project>

3,執(zhí)行 mvn spring-boot:run

在my-parent1目錄執(zhí)行如下命令:

shell> mvn spring-boot:run -pl my-app4

或者:

shell> mvn spring-boot:run -pl test:my-app4
  • test 是 groupId
  • my-app4 是 artifactId

參考

https://stackoverflow.com/questions/41092200/run-mvn-spring-bootrun-from-parent-module

總結(jié)

以上是生活随笔為你收集整理的【sprinb-boot】maven 多模块项目:单独 spring-boot:run 某个模块的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。