Maven
目录
第一章 为什么使用Maven
获取jar包
使用Maven之前,自行在网络中下载jar包,效率较低。如【谷歌、百度、CSDN....】
使用Maven之后,统一在一个地址下载资源jar包【阿里云镜像服务器等...】
添加jar包
使用Maven之前,将jar复制到项目工程中,jar包添加到项目中,相对浪费存储空间
使用Maven之后,jar包统一存储Maven本地仓库,使用坐标方式将jar包从仓库引入到项目中
使用Maven便于解决jar包冲突及依赖问题
第二章 什么是Maven
Maven字面意:专家、内行
Maven是一款自动化构建工具,专注服务于Java平台的项目构建和依赖管理。
依赖管理:jar之间的依赖关系,jar包管理问题统称为依赖管理
项目构建:项目构建不等同于项目创建
项目构建是一个过程【7步骤组成】,项目创建是瞬间完成的
清理:mvn clean
编译:mvn compile
测试:mvn test
报告:
打包:mvn package
安装:mvn install
部署:
第三章 Maven基本使用
3.1 Maven准备
注意:IDEA2019.1.x 最高支持Maven的3.6.0
Maven底层使用Java语言编写的,所有需要配置JAVA_HOME环境变量及Path
将Maven解压非中文无空格目录下
配置MAVEN_HOME环境变量及Path
输入【cmd】,进入命令行窗口,输入【mvn -v】 ,检查Maven环境是否搭建成功
3.2 Maven基本配置
Maven配置文件位置:maven根目录/conf/settings.xml
设置本地仓库【默认:C:/用户家目录/.m2/repository】
<!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>D:\soft\maven</localRepository>
设置阿里云镜像服务器
<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>
</mirrors>
设置使用JDK版本【1.8|JDK8】
<profiles> <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source>