什么是meven?
Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件。
通过使用maven
为什么使用maven?
每次使用到jar包时,每新建一个文档就需要导入相应的jar包,当jar很多时就很繁琐,因此交给maven来管理
maven简单原理
当需要jar包时,从远程仓库下载到本地仓库,项目使用时在本地仓库索引到相应的jar包,减少了项目的内存大小,由于下载地址为境外网址,所以下载到本地时使用镜像网址如阿里,腾讯,百度等
安装
官方下载网址Download Apache Maven – Maven,找与自己jdk对应的版本
我所下载的路径地址,路径中不能有中文
配置环境变量
选择自己的路径
MAVEN_HOME
D:\Program Files\maven\apache-maven-3.8.1
配置变量
%MAVEN_HOME%\bin
打开命令框,win+r,输入cmd,回车,输入 出现一下界面安装成功
mvn-version
配置配置文件
放到自己建的文件夹作为maven仓库
镜像,这么多镜像中选择全部或者几个都行
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>uk</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://uk.maven.org/maven2/</url>
</mirror>
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>nexus</id>
<name>internal nexus repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
<mirror>
<id>net-cn</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://maven.net.cn/content/groups/public/</url>
</mirror>
<mirror>
<id>ibiblio</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>JBossJBPM</id>
<mirrorOf>central</mirrorOf>
<name>JBossJBPM Repository</name>
<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
</mirror>
<mirror>
<id>antelink</id>
<mirrorOf>central</mirrorOf>
<name>antelink Repository</name>
<url>http://maven.antelink.com/content/repositories/central/</url>
</mirror>
<mirror>
<id>openkoala</id>
<mirrorOf>central</mirrorOf>
<name>openkoala Repository</name>
<url>http://nexus.openkoala.org/nexus/content/groups/Koala-release/</url>
</mirror>
<mirror>
<id>tmatesoft</id>
<mirrorOf>central</mirrorOf>
<name>tmatesoft Repository</name>
<url>http://maven.tmatesoft.com/content/groups/public/</url>
</mirror>
<mirror>
<id>mavensync</id>
<mirrorOf>central</mirrorOf>
<name>mavensync Repository</name>
<url>http://mavensync.zkoss.org/maven2/</url>
</mirror>
选中的为注释掉的,不要放在其中,将上述的镜像放在mirrors标签中
关联idea绑定maven路径
后面的override打上对号,才能选择,否则为idea默认路径
第一个选择自己的maven安装路径
第二个找到setting.xml路径
第三个时自己的maven仓库路径
建议在设置以后所有项目都有的的设置时,选择一下选项,设置的为每次新建项目都会生效的配置
如何导入jar包
引入jar包通过该网页Maven Repository: Search/Browse/Explore
以mysql,jar包文件为例
找到所需要的版本
下滑找到maven
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.33</version>
</dependency>
放在中
<dependencies> <!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>8.0.33</version> </dependency> </dependencies>
点击刷新自动下载,在右下角看进程