SSM框架(五):Maven进阶

news2025/2/28 15:31:06

文章目录

  • 一、分模块开发
    • 1.1 分模块开发的意义
    • 1.2 步骤
  • 二、依赖管理
    • 2.1 依赖传递
    • 2.2 可选依赖和排除依赖
  • 三、继承与聚合
    • 3.1 聚合
    • 3.2 继承
    • 3.3 聚合和继承区别
  • 四、属性
    • 4.1 pom文件的依赖使用属性
    • 4.2 资源文件使用属性
  • 五、多环境开发
  • 六、跳过测试
  • 七、私服
    • 7.1 下载与使用
    • 7.2 私服仓库分类
    • 7.3 私服的本地配置与上传文件
  • 八、案例演示


一、分模块开发

1.1 分模块开发的意义

在这里插入图片描述

1.2 步骤

  1. 首先将com.itheima.domain模块拆出来,建立一个新的模块maven_03
  2. 然后在maven_02中的pom文件中引入maven_03的依赖
  3. 将maven_03通过install打包成jar包
  4. 通过maven_02的compile进行编译校验
  5. 最后运行程序是否成功
    在这里插入图片描述

二、依赖管理

2.1 依赖传递

在这里插入图片描述
在这里插入图片描述

2.2 可选依赖和排除依赖

可选依赖是自己用的依赖可以设置为是否给其他人用,解释:这里的optional设置为true表示maven_03_pojo依赖只能自己用,不能被其他人用
在这里插入图片描述

排除依赖是不想用 引用的这个依赖 的下一级依赖,解释:exclusions表示不想用maven_04_dao下的log4j和mybatis依赖

在这里插入图片描述

三、继承与聚合

3.1 聚合

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.2 继承

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.3 聚合和继承区别

在这里插入图片描述

父模块

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>maven_01_parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>

    <!-- 设置聚合工程的子模块:统一管理子模块-->
 <modules>
   <module>../maven_02_ssm</module>
   <module>../maven_03_pojo</module>
 </modules>

    <!-- 父工程的依赖-->
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.2.10.RELEASE</version>
        </dependency>
    </dependencies>

    <!--    定义依赖管理: 子依赖可选择使用-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

子模块

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>maven_02_ssm</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>maven_02_ssm Maven Webapp</name>
  <url>http://maven.apache.org</url>


  <!--  配置当前工程继承parent父工程-->
  <parent>
    <groupId>org.example</groupId>
    <artifactId>maven_01_parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <!--  parent父工程pom文件的位置-->
    <relativePath>../maven_01_parent/pom.xml</relativePath>
  </parent>

  <dependencies>

    <dependency>
      <groupId>org.example</groupId>
      <artifactId>maven_03_pojo</artifactId>
      <version>1.0-SNAPSHOT</version>
      <!-- 设置可选依赖:true表示仅自己使用,其他人无法使用 -->
      <optional>false</optional>
      <!-- 设置排除依赖:表示不想使用maven_03_pojo依赖下的mybatis依赖 -->
      <exclusions>
        <exclusion>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <!-- 继承父类的依赖,不用写版本号,父类已写好-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>

  </dependencies>
  <build>
    <finalName>maven_02_ssm</finalName>
    <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>
  </build>
</project>

四、属性

在这里插入图片描述

在这里插入图片描述

4.1 pom文件的依赖使用属性

在这里插入图片描述
在这里插入图片描述

4.2 资源文件使用属性

这里使用pom.xml文件配置src/mian/resourses下的jdbc.properties文件的属性,即使用pom文件配置连接数据库需要的参数
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

五、多环境开发

Maven提供配置多种环境的设定,帮助开发者使用过程中快速切换环境
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
一定要注意:mvn 命令要在指定模块下运行,不然找不到环境
在这里插入图片描述

六、跳过测试

应用场景:功能未开发完、快速打包…
方式一:
在这里插入图片描述
方式二:
在这里插入图片描述
方式三:
在这里插入图片描述

七、私服

7.1 下载与使用

Nexus下载地址:https://help.sonatype.com/repomanager3/download
在这里插入图片描述

下载解压后会有nexus-3.30.1-01和sonatype-work文件夹,在nexus-3.30.1-01\bin目录下打开cmd输入指令nexus.exe /run nexus启动服务器
在这里插入图片描述

7.2 私服仓库分类

在这里插入图片描述

7.3 私服的本地配置与上传文件

第一步:建立两个maven2仓库,并且在maven-public里面将建好的两个仓库交给其管理,记得点击save保存

在这里插入图片描述
在这里插入图片描述

第二步:在本地的maven的setting.xml(apache-maven-3.3.9\conf下)文件中配置,访问私服的仓库的用户名和密码

在这里插入图片描述

同样在setting.xml中配置私服的地址,圈红部分改为maven-public

在这里插入图片描述

第三步:在父工程的pom文件中

在这里插入图片描述

最后,可以看到私有仓库itheima-release已经上传了文件

在这里插入图片描述

注意:可以修改pom.xml文件的version版本为release(发布版本)或snapshot(快照版本)格式,指定放在私服的哪个仓库中

在这里插入图片描述

其次:想要配置访问中央服务器的地址,这里可以改为阿里的

在这里插入图片描述

八、案例演示

父工程maven_01_parent

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>maven_01_parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>

    <!-- 3.设置聚合工程的子模块:统一管理子模块-->
 <modules>
   <module>../maven_02_ssm</module>
   <module>../maven_03_pojo</module>
 </modules>

    <!-- 4.父工程的依赖-->
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <!--    9.使用属性  -->
            <version>${Spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${Spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${Spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.6</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.0</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.16</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.0</version>
        </dependency>
    </dependencies>

    <!--    6.定义依赖管理: 子依赖可选择使用-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <!--    8.定义属性  -->
    <properties>
        <Spring.version>5.2.10.RELEASE</Spring.version>
        <junit.version>4.12</junit.version>
        <jdbc.username>root</jdbc.username>
    </properties>

    <build>
        <!--10.配置指定目录下的文件也能使用上面的属性-->
        <resources>
            <!--设置资源目录,并设置能够解析${}-->
            <resource>
                <!-- <directory>../maven_02_ssm/src/main/resources</directory>-->
                <!-- <directory>../maven_03_pojo/src/main/resources</directory>-->
                <!-- 上述可以简化成${project.basedir}-->
                <directory>${project.basedir}/src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <!--13.跳过测试-->
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <!--true表示跳过所有测试-->
                    <skipTests>false</skipTests>
                    <!--排除掉不参与测试的内容-->
                    <excludes>
                        <exclude>**/BookServiceTest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!--12.配置多环境-->
    <profiles>
        <!--开发环境-->
        <profile>
            <id>env_dep</id>
            <properties>
                <jdbc.url>jdbc:mysql://127.1.1.1:3306/ssm_db</jdbc.url>
            </properties>
            <!--设定是否为默认启动环境-->
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <!--生产环境-->
        <profile>
            <id>env_pro</id>
            <properties>
                <jdbc.url>jdbc:mysql://127.2.2.2:3306/ssm_db</jdbc.url>
            </properties>
        </profile>
        <!--测试环境-->
        <profile>
            <id>env_test</id>
            <properties>
                <jdbc.url>jdbc:mysql://127.3.3.3:3306/ssm_db</jdbc.url>
            </properties>
        </profile>
    </profiles>

    <!--14.配置当前工程保存在私服中的具体位置-->
    <distributionManagement>
        <repository>
            <id>itheima-Release</id>
            <url>http://localhost:8081/repository/itheima-Release/</url>
        </repository>
        <snapshotRepository>
            <id>itheima-Snapshot</id>
            <url>http://localhost:8081/repository/itheima-Snapshot/</url>
        </snapshotRepository>
    </distributionManagement>

</project>

子工程maven_02_ssm

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>maven_02_ssm</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>maven_02_ssm Maven Webapp</name>
  <url>http://maven.apache.org</url>


  <!-- 5. 配置当前工程继承parent父工程-->
  <parent>
    <groupId>org.example</groupId>
    <artifactId>maven_01_parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <!--  parent父工程pom文件的位置-->
    <relativePath>../maven_01_parent/pom.xml</relativePath>
  </parent>

  <dependencies>

    <dependency>
      <groupId>org.example</groupId>
      <artifactId>maven_03_pojo</artifactId>
      <version>1.0-SNAPSHOT</version>
      <!-- 1.设置可选依赖:true表示仅自己使用,其他人无法使用 -->
      <optional>false</optional>
      <!-- 2.设置排除依赖:表示不想使用maven_03_pojo依赖下的mybatis依赖 -->
      <exclusions>
        <exclusion>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <!-- 7.继承父类的依赖,不用写版本号,父类已写好-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>

  </dependencies>
  <build>
    <finalName>maven_02_ssm</finalName>
    <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>
      <!--11.打包时忽略检查web.xml文件-->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.3</version>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

子工程maven_03_pojo

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>maven_03_pojo</artifactId>
  <packaging>jar</packaging>
  <version>1.0-RELEASE</version>
  <name>maven_03_pojo Maven Webapp</name>
  <url>http://maven.apache.org</url>

  <!--  5.配置当前工程继承parent父工程-->
  <parent>
    <groupId>org.example</groupId>
    <artifactId>maven_01_parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../maven_01_parent/pom.xml</relativePath>
  </parent>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>maven_03_pojo</finalName>
  </build>
</project>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1278202.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

禁止谷歌浏览器自动更新

禁止谷歌浏览器自动更新 在使用Python包selenium的时候浏览器版版本发生变化后产生很多问题如&#xff1a; 1、直接版本不对应无法运行 2、版本不一致导致debug启动浏览器超级慢 这里是已谷歌浏览器为代表的。 禁止自动更新的方法如下&#xff1a; 1、WinR调出运行&#x…

一小时玩转【负载均衡】

&#x1f604;作者简介&#xff1a; 小曾同学.com,一个致力于测试开发的博主⛽️&#xff0c;主要职责&#xff1a;测试开发、CI/CD 如果文章知识点有错误的地方&#xff0c;还请大家指正&#xff0c;让我们一起学习&#xff0c;一起进步。 &#x1f60a; 座右铭&#xff1a;不…

SpringBoot 是如何启动一个内置的Tomcat

为什么说Spring Boot框架内置Tomcat 容器,Spring Boot框架又是怎么样去启动Tomcat的?我简单总结下学习过程。 一:简单了解SpringBoot的启动类 我们都知道Spring Boot框架的启动类上是需要使用 @SpringBootApplication 注解标注的, @SpringBootApplication 是一个复合注解…

Redis--10--Pipeline

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 Pipeline举例比较普通模式与 PipeLine 模式小结&#xff1a; Pipeline 前面我们已经说过&#xff0c;Redis客户端执行一条命令分为如下4个部分:1&#xff09;发送命…

前端入门(五)Vue3组合式API特性

文章目录 Vue3简介创建Vue3工程使用vite创建vue-cli方式 常用 Composition API启动项 - setup()setup的执行时机与参数 响应式原理vue2中的响应式vue3中的响应式ref函数reactive函数reactive与ref对比 计算属性 - computed监视属性 - watchwatchEffect Vue3生命周期自定义hook函…

滑动平均窗口的定义,优点,缺点,以及目前的应用!!

文章目录 前言一、滑动平均窗口的优点二、滑动平均窗口的缺点三、滑动平均窗口的应用 前言 滑动平均窗口是一种数据处理方法&#xff0c;它以固定的窗口大小对数据进行移动&#xff0c;并在每个窗口内计算数据的平均值。这种方法主要用于平滑数据&#xff0c;减小数据波动的影…

基于SpringBoot的仓库管理系统设计与实现附带源码和论文

博主24h在线&#xff0c;想要源码文档部署视频直接私聊&#xff0c;全网最低价&#xff0c;9.9拿走&#xff01; 【关键词】仓库管理系统&#xff0c;jsp编程技术&#xff0c;mysql数据库&#xff0c;SSM&#xff0c;Springboot 目 录 摘 要 Abstract 第1章 绪论 1.1 课题…

阿里云服务器跨区域迁移(多数据盘)

方法一. 复制镜像&#xff0c;共享镜像&#xff08;只有系统盘没有数据盘的情况&#xff01;&#xff09; 正常阿里云同区域服务器迁移只需要选择共享镜像即可&#xff0c;但是由于新老服务器区域限制所以需要先复制到新服务器区域再进行共享 选择服务器实例先创建后复制 比如…

Linux 内核源码各版本下载

下载地址&#xff1a; kernel/git/stable/linux.git - Linux kernel stable treehttps://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/refs/ 1. Linux 内核的基本概念&#xff1a; 内核是什么&#xff1f; 内核是操作系统的核心部分&#xff0c;负责管理系统…

网络虚拟化场景下网络包的发送过程

网络虚拟化有和存储虚拟化类似的地方&#xff0c;例如&#xff0c;它们都是基于 virtio 的&#xff0c;因而在看网络虚拟化的过程中&#xff0c;会看到和存储虚拟化很像的数据结构和原理。但是&#xff0c;网络虚拟化也有自己的特殊性。例如&#xff0c;存储虚拟化是将宿主机上…

物流单管理系统软件物流单打印,物流单打印模板,佳易王物流快运单管理软件下载

物流单管理系统软件物流单打印&#xff0c;物流单打印模板&#xff0c;佳易王物流快运单管理软件下载 软件试用版下载或技术支持可以点击最下方官网卡片 上图&#xff1a;在物流开单时&#xff0c;可以先输入电话&#xff0c;如果之前存在该托运人信息&#xff0c;则可以一键…

hbase Master is initializing

问题如下&#xff1a; ERROR: org.apache.hadoop.hbase.PleaseHoldException: Master is initializing ERROR: org.apache.hadoop.hbase.PleaseHoldException: Master is initializingat org.apache.hadoop.hbase.master.HMaster.checkInitialized(HMaster.java:2452)at org.…

P1 什么是链表 C语言简单易懂

目录 前言 01 什么是链表 02 数组的特点 03 数组的缺点 3.1 删除数组其中一个元素 3.2 数组增加某个节点 04 链表 前言 &#x1f3ac; 个人主页&#xff1a;ChenPi &#x1f43b;推荐专栏1: 《 C 》✨✨✨ &#x1f525; 推荐专栏2: 《 Linux C应用编程&#xff08;概念…

Web自动化测试详解

做测试的同学们都了解&#xff0c;做Web自动化&#xff0c;我们主要用Selenium或者是QTP。 有的人可能就会说&#xff0c;我没这个Java基础&#xff0c;没有Selenium基础&#xff0c;能行吗&#xff1f;测试虽然属于计算机行业&#xff0c;但其实并不需要太深入的编程知识&…

神经网络 代价函数

神经网络 代价函数 首先引入一些便于稍后讨论的新标记方法&#xff1a; 假设神经网络的训练样本有 m m m个&#xff0c;每个包含一组输入 x x x和一组输出信号 y y y&#xff0c; L L L表示神经网络层数&#xff0c; S I S_I SI​表示每层的neuron个数( S l S_l Sl​表示输出…

论文编写软件latex安装教程

目录 1.下载安装包2.安装texlive 本人系统为windows&#xff0c;本教程基于windows系统&#xff0c;如果是其它系统请参考对应教程&#xff0c;注意选择对应系统的安装包&#xff01; 1.下载安装包 有三种集成环境安装包 texlive 是主流的环境&#xff0c;集成了较多的包&…

百度飞桨(张江)人工智能产业赋能中心入驻申请

中心如何赋能 百度飞桨&#xff08;张江&#xff09;人工智能产业赋能中心是浦东“大企业开放创新中心计划”首批企业代表&#xff0c;百度和张江集团将联合为入驻初创企业及生态合作伙伴提供以下服务&#xff1a; 降低AI使用门槛 通过“百度飞桨人工智能公共技术平台”&#x…

基于SpringBoot的企业客户管理系统的设计与实现

摘 要 本论文主要论述了如何使用JAVA语言开发一个企业客户管理系统&#xff0c;本系统将严格按照软件开发流程进行各个阶段的工作&#xff0c;采用B/S架构&#xff0c;面向对象编程思想进行项目开发。在引言中&#xff0c;作者将论述企业客户管理系统的当前背景以及系统开发的目…

二维粒子群算法航线规划

GitHub - gabrielegilardi/PathPlanning: Implementation of particle swarm optimization (PSO) for path planning when the environment is known.

亚马逊云科技推出新一代自研芯片

北京——2023 年12月1日 亚马逊云科技在2023 re:Invent全球大会上宣布其自研芯片家族的两个系列推出新一代&#xff0c;包括Amazon Graviton4和Amazon Trainium2&#xff0c;为机器学习&#xff08;ML&#xff09;训练和生成式人工智能&#xff08;AI&#xff09;应用等广泛的工…