`` 在java中Maven就是一个包管理工具,在没有包管理工具时,我们要做一个java项目,需要第三方依赖包,将别人打包好的Jar包下载到本地,然后手动指定给项目.操作比较麻烦,比如版本控制,有的甚至还有其他包的依赖,属实是繁琐,技术是不断地迭代的,所以就出现了Maven,用了Maven之后,需要什么包,直接在pom.xml中添加xml代码,指定包名 版本等.很方便我们开发人员进行项目的部署以及开发.
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <version>8.0.16version>//版本
- dependency>
Maven默认为从中央 仓库下载Jar包的,中央仓库在国外,所以速度很慢.
我们为什么要学习Maven?
2.Maven 简介
Maven 是 Apache 软件基金会的一个开源项目,是一个优秀的项目构建工具,它
用来帮助开发者管理项目中的 jar,以及 jar 之间的依赖关系、完成项目的编译、
测试、打包和发布等工作。
3.如何找到Jar包的位置?
在我们生活中,高得地图为什么能够准确的找到我们想要找到的位置呢?还有比较准确的位置导航,是不是因为每个位置都有一个属于自己的坐标,我们在输入所要查询的地点其实是默认给了它一个位置坐标,Maven中也是这样的原理,maven 给每个 jar 定义了唯一的标志,这个在 maven 中叫做项目的坐标,通过这个坐标可以找到你需要 用到的任何版本的 jar 包。
- "1.0" encoding="UTF-8"?>
- <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.0modelVersion>
-
- <groupId>com.examplegroupId>
- <artifactId>mavenDemoartifactId>
- <version>1.0.0version>
- <name>mavenDemoname>
- <packaging>warpackaging>
-
-
- <properties>
-
- <maven.compiler.target>1.8maven.compiler.target>
- <maven.compiler.source>1.8maven.compiler.source>
- <junit.version>5.6.2junit.version>
- properties>
-
-
- <dependencies>
-
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <version>8.0.16version>
- <type>jartype>
- dependency>
-
- <dependency>
- <groupId>commons-fileuploadgroupId>
- <artifactId>commons-fileuploadartifactId>
- <version>1.3.1version>
- <type>jartype>
- <scope>compilescope>
- dependency>
-
- <dependency>
- <groupId>javax.servletgroupId>
- <artifactId>javax.servlet-apiartifactId>
- <version>3.1.0version>
- <scope>providedscope>
- dependency>
-
- <dependency>
- <groupId>com.examplegroupId>
- <artifactId>myUtilartifactId>
- <version>1.0-SNAPSHOTversion>
- dependency>
-
- dependencies>
-
- <build>
-
- <plugins>
- <plugin>
- <groupId>org.apache.maven.pluginsgroupId>
- <artifactId>maven-war-pluginartifactId>
- <version>3.3.0version>
- plugin>
- plugins>
- build>
- project>

基本流程:
1.安装JDk,较好的网络环境
2.下载Maven服务器
3.对Maven环境进行配置
4.在电脑中创建一个存储从镜像仓库下载Jar包的文件夹,一般我们称为”仓库(repository),在 maven 的服务器解压的文件中找到 conf 文件夹下的settings.xml 文件进行修改,如下图所示:

配置阿里云 maven 镜像仓库,下载速度更快
- <mirror>
- <id>alimavenid>
- <name>aliyun mavenname>
- <url>http://maven.aliyun.com/nexus/content/groups/public/url>
- <mirrorOf>centralmirrorOf>
- mirror>
5.从idea中设置Maven




6.Pom.xml 配置
maven 仓库官网(http://mvnrepository.com/)
7.Maven命令
1. compile 编译
2. clean
删除 target
3. package 打包
4. install
把项目 install 到本地仓库
5. test
运行测试代码