Maven 多 POM 项目

问题描述

我有多个 Maven 项目。就我而言,没有父 pom。所有其他项目都相互依赖。这是我的项目结构

项目 1 ---- pom.xml(项目 2 jar 依赖于项目 1)

项目 2 ---- pom.xml(项目 3 jar 依赖于项目 2)

项目 3 ---- pom.xml(项目 5 jar 依赖于项目 3)

项目 4 ---- pom.xml(war 文件)

项目 5 ---- pom.xml(项目 5 jar 依赖于项目 1)

项目 6 ---- pom.xml(项目 5 jar 依赖于项目 6)

项目 4 是我的主要项目,项目 4 将包含将在服务器上执行的 war 文件

我的问题是父项目(项目 4)的 POM 结构与所有其他项目的构建执行是什么?

解决方法

您应该将每个项目安装或部署为 jar,并将依赖项添加到父项目并打包为 war。

例如在项目 5 pom.xml 中:

<dependencies>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>project1</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>project3</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>project6</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

并在项目 4 pom.xml 中添加所有依赖项:

<dependencies>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>project1</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>project2</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>project3</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>project5</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>project6</artifactId>
        <version>1.0.0</version>
    </dependency>
    ......
</dependencies>

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...