1.Maven仓库的分类
Maven仓库可以分为本地仓库和远程仓库两类
1.1【本地仓库】
本地仓库相当于一个缓存,在电脑上是一个文件夹,我们可以设置这个文件夹的路径(具体怎么设置会在下面的配置体现),工程第一次需要某种jar包时,会从远程仓库(互联网)下载并保存到本地仓库中(在程序员的电脑上),当第二次使用时,不需要去远程仓库下载,会先去本地仓库中找,如果找不到才会去远程仓库上下载。
1.2【远程仓库】
远程仓库又分为中央仓库和私服两类
1.2.1【中央仓库】
中央仓库中的jar包由专业团队(Maven团队)维护,中央仓库中存放了全世界大多数流行的开源软件的jar包,是Maven默认的远程仓库
1.2.2【私服】
在公司内部架设一台服务器,里面存放了所有需要的jar包,对外公开,供终端下载。例如阿里云
2.Maven仓库的配置
2.1Maven配置本地仓库
修改安装Maven的路径下的config文件下的setting.xml文件的localReporsity标签(我下载的这个版本是在50多行)
<localRepository>自己设置本地仓库的路径</localRepository>
我设置到了D:\maven\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:\maven\repository</localRepository>
2.2Maven配置远程仓库镜像
Maven默认的远程仓库是Maven团队维护的中央仓库,由于网络原因,去中央仓库下载jar包需要到国外的网站,不太便捷,速度慢,于是我们可以选择把国内的阿里云的Maven仓库作为中央仓库镜像
修改安装Maven的路径下的config文件下的setting.xml文件的mirrors标签(我下载的这个版本是在50多行)
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
其中各个标签的含义是:
id:当前镜像的唯一标识
mirrorOf:将哪个远程仓库当做中央仓库镜像,中央仓库的id是central,所以将阿里云的Maven仓库设置为中央仓库镜像时,其值必须设置为central
name:为当前的中央仓库镜像起一个名字,便于开发者阅读
url:阿里云Maven仓库的地址
<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>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>