IDEA创建简单maven子父工程

本文介绍了如何使用Maven创建一个多模块项目,包括父工程与子工程的建立,以及各模块间的依赖配置。通过配置pom.xml文件,实现了netDisc-core、netDisc-common、netDisc-entity和netDisc-util等模块的相互依赖,并展示了netDisc-web对其他模块的依赖关系。此外,还详细展示了如何在pom.xml中管理依赖和版本。
摘要由CSDN通过智能技术生成

1、最终效果

在这里插入图片描述

2、依赖关系

netDisc-web依赖netDisc-common、netDisc-core、netDisc-enetity、netDisc-util。
netDisc-core依赖netDisc-common、netDisc-entity、netDisc-util
netDisc-common依赖netDisc-entity、netDisc-util

3、创建过程

1、创建父工程

file → new Project → Maven 一路next
在这里插入图片描述

2、创建子工程

在父工作上右击 new - module -maven 一路next
在这里插入图片描述

3、添加工程之间的依赖

3.1 父工程pom.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
    <artifactId>netDisc</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>netDisc-core</module>
        <module>netDisc-common</module>
        <module>netDisc-util</module>
        <module>netDisc-entity</module>
        <module>netDisc-web</module>
    </modules>
    <properties> <!-- 声明属性,对 Spring 的版本进行统一管理 -->
        <netDisc.version>4.3.20.RELEASE</netDisc.version>
        <!-- 声明属性,对 SpringSecurity 的版本进行统一管理 -->
        <netDiscsecurity.version>4.2.10.RELEASE</netDiscsecurity.version>
    </properties>

    <dependencyManagement>
        <dependencies>
          <!-- 这里放需要引入的jar包-->
        </dependencies>
    </dependencyManagement>
</project>
3.2 子工程 以netDisc-core 为例(注意打包方式以效果图中标注的打包方式为准)
<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>netDisc</artifactId>
        <groupId>org.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>
    <artifactId>netDisc-core</artifactId>

    <dependencies>
        <!--公共模块-->
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>netDisc-common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!-- 实体模块-->
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>netDisc-entity</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!-- 工具模块-->
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>netDisc-util</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

其他子工程这里就不写了,和上面例子中的子工程大同小异,需要哪个添加哪个包到pom.xml即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值