maven 聚合 与 继承 笔记

60 篇文章 0 订阅
50 篇文章 0 订阅
本文详细介绍了Maven的聚合与继承概念。聚合用于管理多个项目模块,通过在管理模块的pom.xml中列出子模块来构建整个项目。继承则允许子模块继承父模块的配置,如依赖版本,简化重复配置。在实际应用中,聚合与继承可以结合使用,以高效管理和构建大型项目。
摘要由CSDN通过智能技术生成

maven 聚合

是用一个项目模块 来管理其他的项目模块。这个管理模块不是其他模块的 父类 项目模块。这个模块不用写什么代码,只用来管理。

要实现管理模块 要在它的pom文件中 写出

  <!--定义该工程用于进行构建管理-->
    <packaging>pom</packaging>

    <!--管理的工程列表-->
    <modules>
        <!--具体的工程名称-->
        <module>../ssm_controller</module>
        <module>../ssm_service</module>
        <module>../ssm_dao</module>
        <module>../ssm_pojo</module>
    </modules>

聚合项目模块 打 包 方式 必须写成 pom格式

注意事项:参与聚合操作的模块最终执行顺序与模块间的依赖关系有关,与配置顺序无关


maven 继承

  • 作用:通过继承可以实现在子工程中沿用父工程中的配置

    • maven中的继承与java中的继承相似,在子工程中配置继承关系
  • 制作方式:

    - 在子工程中声明其父工程坐标与对应的位置

    <!--定义该工程的父工程-->
    <parent>
        <groupId>com.itheima</groupId>
        <artifactId>ssm</artifactId>
        <version>1.0-SNAPSHOT</version>
        <!--填写父工程的pom文件-->
        <relativePath>../ssm/pom.xml</relativePath>
    </parent>
    

继承依赖定义**

在父工程中定义依赖管理

<!--声明此处进行依赖管理-->
<dependencyManagement>
    <!--具体的依赖-->
    <dependencies>
        <!--spring环境-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.1.9.RELEASE</version>
        </dependency>
    <dependencies>
<dependencyManagement>

继承依赖使用**

在子工程中定义依赖关系,无需声明依赖版本,版本参照父工程中依赖的版本

<dependencies>
    <!--spring环境-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
</dependencies>

父项目模块 的 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>com.itheima</groupId>
    <artifactId>ssm</artifactId>
    <version>1.0-SNAPSHOT</version>
    <!--定义该工程用于进行构建管理-->
    <packaging>pom</packaging>

    <!--管理的工程列表-->
    <modules>
        <!--具体的工程名称-->
        <module>../ssm_controller</module>
        <module>../ssm_service</module>
        <module>../ssm_dao</module>
        <module>../ssm_pojo</module>
    </modules>

    <!--声明此处进行依赖管理-->
    <dependencyManagement>
        <!--具体的依赖-->
        <dependencies>
            <!--添加自己的工程模块依赖-->
            <dependency>
                <groupId>com.itheima</groupId>
                <artifactId>ssm_pojo</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>

            <dependency>
                <groupId>com.itheima</groupId>
                <artifactId>ssm_dao</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>

            <dependency>
                <groupId>com.itheima</groupId>
                <artifactId>ssm_service</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>


            <!--spring环境-->
            <!--spring环境-->
            <!--spring环境-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>5.1.9.RELEASE</version>
            </dependency>


            <!--mybatis环境-->
            <!--mybatis环境-->
            <!--mybatis环境-->
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <version>3.5.3</version>
            </dependency>
            <!--mysql环境-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.47</version>
            </dependency>
            <!--spring整合jdbc-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>5.1.9.RELEASE</version>
            </dependency>
            <!--spring整合mybatis-->
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis-spring</artifactId>
                <version>2.0.3</version>
            </dependency>
            <!--druid连接池-->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.1.16</version>
            </dependency>
            <!--分页插件坐标-->
            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper</artifactId>
                <version>5.1.2</version>
            </dependency>

            <!--springmvc环境-->
            <!--springmvc环境-->
            <!--springmvc环境-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>5.1.9.RELEASE</version>
            </dependency>
            <!--jackson相关坐标3个-->
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.9.0</version>
            </dependency>
            <!--servlet环境-->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.1.0</version>
                <scope>provided</scope>
            </dependency>


            <!--其他组件-->
            <!--其他组件-->
            <!--其他组件-->
            <!--junit单元测试-->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <!--spring整合junit-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>5.1.9.RELEASE</version>
            </dependency>
        </dependencies>

    </dependencyManagement>

    <build>
        <pluginManagement>
            <!--设置插件-->
            <plugins>
                <!--具体的插件配置-->
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <port>80</port>
                        <path>/</path>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>

现在 继承后 tomcat启动 还是要在controller层启动

继承后 在子项目模块中 还是要写出需要用到的依赖坐标,但因为 版本在父工程里写了,就不用在子工程里写版本了

controller的pom里 打包方式不是 war 不会出现 80的端口访问路径,跳转链接


继承的资源**

groupId:项目组ID,项目坐标的核心元素

version:项目版本,项目坐标的核心因素

description:项目的描述信息

organization:项目的组织信息

inceptionYear:项目的创始年份

url:项目的URL地址

developers:项目的开发者信息

contributors:项目的贡献者信息

distributionManagement:项目的部署配置

issueManagement:项目的缺陷跟踪系统信息

ciManagement:项目的持续集成系统信息

scm:项目的版本控制系统西溪

malilingLists:项目的邮件列表信息

properties:自定义的Maven属性

dependencies:项目的依赖配置

dependencyManagement:项目的依赖管理配置

repositories:项目的仓库配置

build:包括项目的源码目录配置、输出目录配置、插件配置、插件管理配置等

reporting:包括项目的报告输出目录配置、报告插件配置等


继承与聚合**

作用

  • 聚合用于快速构建项目

  • 继承用于快速配置

相同点:

  • 聚合与继承的pom.xml文件打包方式均为pom,可以将两种关系制作到同一个pom文件中

  • 聚合与继承均属于设计型模块,并无实际的模块内容

不同点:

  • 聚合是在当前模块中配置关系,聚合可以感知到参与聚合的模块有哪些

  • 继承是在子模块中配置关系,父模块无法感知哪些子模块继承了自己

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

普希托夫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值