Maven 相关配置
maven安装目录
配置本地仓库地址
- 找到settings.xml中的 localRepository 本地仓库 settings.xml在maven安装目录中的conf目录下
- 本地创建文件夹(想在哪在哪) 创建一个空文件夹作为maven的本地仓库
- 添加配置如下
maven和IDEA集成(通过IDEA创建maven项目)
1.选择项目类型和骨架
2.输入坐标信息
3.配置maven工具的信息
4. 项目路径
5. 完成创建
6. 补全项目结构 需要选择文件夹类型
注意:
-
选择 Enable Auto-Import
-
默认创建出来的项目结构不完善 需要按照maven规范补全
pom.xml文件配置
1.定义Spring的版本
<!--properties 全局配置 编码格式 编译版本 jar包版本等-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<!--1.定义Spring的版本-->
<spring-version>5.0.8.RELEASE</spring-version>
</properties>
2.使用定义的统一版本 使用$符号取值
使用的是properties标签中声明的版本
<!--dependencies 依赖-->
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<!--2.使用定义的统一版本-->
<version>${spring-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-version}</version>
</dependency>
</dependencies>
不使用$ 直接在依赖中声明版本
<dependencies>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
Maven Projects maven管理界面
Lifecycle 生命周期
手动刷新
在导入新的jar后可以手动刷新