Maven 基础知识点笔记

8 阅读1分钟

1. 项目信息字段

标签含义如何填写
<parent>指定父 POMSpring Boot 项目直接写 spring-boot-starter-parent
<groupId>项目组织唯一标识公司/组织/学校域名倒写
<artifactId>项目唯一名称与项目文件夹一致
<version>项目版本号1.0 / 1.0-SNAPSHOT
<name>项目名称可写中文
<description>项目描述可写中文
<packaging>打包方式jar / war / pom
relativePath相对路径,若为空则从本地仓库或远程仓库拉取,如果不为空优先从指定的地方拉去比如父模块什么都不填:<relativePath/>,比如子模块要填父模块的pom.xml地址:<relativePath>../pom.xml</relativePath>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.3</version>
    <relativePath/>
</parent>

<groupId>com.akbar</groupId>
<artifactId>sky-take-out</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Sky 外卖管理系统</name>
<description>一个基于 Spring Boot 的外卖管理系统,用于学习和毕业设计</description>
<packaging>jar</packaging>

2.依赖范围

image.png

  • log4j:所有阶段我们都需要打印日志。
  • junit:junit只在测试阶段使用。
  • servlet-api:不能打包,因为tomcat中也有servlet-api,为了避免版本冲突,servlet-api不参与打包。
  • jdbc:我们写代码的时候根本没有用过jdbc这个类名,因为jdbc只是一个驱动,所以它只需要参与打包阶段,注意不能不打包,因为MySQL等数据库需要它。

3.项目构建的生命周期

image.png

  • 安装:这里的install(安装)指的是我们把项目打包好以后别的项目可以导入我们的项目作为依赖。

4.插件

image.png

比如springboot 项目有这样的插件:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

5.模块划分

B站视频地址:www.bilibili.com/video/BV1Ah…