目录
2.对项目使用compile命令进行编译,看看新的文件会在哪里产生?
7.Idea中使用Maven,在控制台输出的是乱码如何解决?
1.导入依赖A时如果这个依赖又依靠依赖B,此时应该再去导入依赖B吗?
一.作用
1.提供标准项目结构,使用Maven创建出来的工程模板如下:

2.提供标准项目流程(编译-测试-打包-安装一条龙一键服务)
3.自动导入与删除导入jar包(在pom文件中操作)
二.安装
1.下载rar包解压到某目录
2.创建MAVEN_HOME环境变量

3.path增添%MAVEN_HOME%\bin

4.管理员cmd输入mvn -v查看配置

5.配置本地仓库与配置阿里云仓库
maven安装目录-conf-settings.xml文件中内容全删了放下面这些(配置了jdk17)
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>D:\apache-maven-3.6.1\mvn_localrepository</localRepository>
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk-17</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>17</jdk>
</activation>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
</settings>
6.IDEA配置Maven仓库
先退出工程:File→Close Project
找到Customize-AllSettings进行全局设置:


三.使用
1.创建新的Maven项目(选择快速开始的项目)

2.对项目使用compile命令进行编译,看看新的文件会在哪里产生?
会把项目编译到新文件到target里面去


3.需要认识的命令
clean:清理,清除target目录
test:测试代码
package: 打包(产生jar包在target目录下)
install:把当前项目安装到maven的本地仓库
4.Maven对项目执行不同命令的生命周期特点?
同一生命周期内,执行后面命令,前面的命令也会执行
compile-test-package-install
如果执行安装命令,会先执行编译-测试-打包命令
5.如何导入工程外的Maven?
在项目结构处导入项目的pom文件即可
6.如何直观地查看Maven导入了哪些工程或哪些jar包?
pom文件中,右键Diagram-show可以看依赖图

7.Idea中使用Maven,在控制台输出的是乱码如何解决?
设置-maven-runner-VMOptions填写:-Dfile.encoding=GBK

四.POM文件细节
1.导入依赖A时如果这个依赖又依靠依赖B,此时应该再去导入依赖B吗?
2.能够导入本地的模块吗?
3.如何排除导入的模块中不需要的依赖?
4.如何设置依赖的作用范围?
<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>maven-module1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!--
1.由于依赖传递特性,不需要再去导入依赖中的依赖,全部依赖自动导入
下面引入classic这个依赖也能自动引入slf4j和core依赖
-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.14</version>
</dependency>
<!--2.和导入仓库中的依赖一样,也能够导入仓库中自己安装的工程模块,同时该模块中的依赖也将被导入-->
<dependency>
<groupId>org.example</groupId>
<artifactId>maven-module2</artifactId>
<version>1.0-SNAPSHOT</version>
<!--
3.排除依赖,也就是在本工程中不需要导入工程中的jar包
使用exclusions标签,一个个排除依赖,不需要写版本号-->
<exclusions>
<exclusion>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--4.使用scope标签设置依赖范围,设置为test则只能在测试程序中起效-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>