POM MOUDlES

In a Maven pom.xml file, <modules> is used to define the modules of a multi-module project. This is common in larger projects that are split into multiple sub-projects, each of which has its own pom.xml. The parent pom.xml (often in the root directory) lists these sub-projects under the <modules> section.

Here is a basic example of how <modules> can be used in a 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>parent-project</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>module-a</module>
        <module>module-b</module>
    </modules>

    <dependencies>
        <!-- Parent-level dependencies -->
    </dependencies>

    <build>
        <plugins>
            <!-- Parent-level plugins -->
        </plugins>
    </build>
</project>

Child pom.xml for module-a

 
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.example</groupId>
        <artifactId>parent-project</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>module-a</artifactId>

    <dependencies>
        <!-- Module-specific dependencies -->
    </dependencies>
</project>

Child pom.xml for module-b

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.example</groupId>
        <artifactId>parent-project</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>module-b</artifactId>

    <dependencies>
        <!-- Module-specific dependencies -->
    </dependencies>
</project>

Key Points:

  • Parent <pom.xml>: Contains the <modules> section listing all sub-modules.
  • Child <pom.xml>: Each module has its own pom.xml file and refers to the parent project.
  • Hierarchy: The parent-child relationship helps manage dependencies, plugins, and build configurations centrally.

This setup allows you to manage complex projects more easily, sharing configurations and dependencies among multiple modules.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值