1 本地仓库的配置
在第一篇中咱们介绍过,Maven的仓库有三类,这里再也不介绍。浏览器
一、要建立本地仓库咱们须要有相应的jar包文件,本人通过长时间的寻找和积累,已经有了一个jar包仓库,现将此jar包提供给你们使用。下载地址:http://pan.baidu.com/s/1jH77z2Q。maven
二、将下载先来的仓库文件解压到你要存放的地方。文件解压后有1.13G大小,请合理选择存放地方。解压后目录如图:post
三、配置Maven的本地仓库。url
在Maven的安装目录下的conf目录下找到settings.xml文件,打开该文件,修改以下部分:spa
2私服仓库的配置
私服仓库的配置比较复杂。操作系统
一、 下载sonatype Nexus来搭建私服3d
咱们能够本身去下载https://www.sonatype.com/download-oss-sonatype。下载以下文件。下载速度比较慢,这里提供一个本身的百度云盘下载连接,你们能够去网盘下载:http://pan.baidu.com/s/1gfcLFzl。code
下载该文件后对该文件进行解压缩,进入D:\nexus-2.14.4-03-bundle\nexus-2.14.4-03\bin\jsw目录下能够看到不少文件夹,而后根据本身机器的操做系统选择相应的目录,本文以64位Windows操做系统为例。server
2 安装nexus服务
运行该目录下的install-nexus.bat文件(右击以管理员身份运行),该窗口会一闪而过,而后运行start-nexus.bat文件,等该文件运行窗口关闭后,在浏览器访问http://127.0.0.1:8081/nexus/。就会看到该欢迎页面。
三、建立私服仓库
而后点击右上角的log in 进行登陆,默认用户名:admin,密码:admin123。登录后在右边选项卡 Views/Repositories下选择 Repositories就能够看到全部仓库,该地方不作过多的介绍,只介绍如何进行私服仓库配置。
选择上方的add按钮,而后选择hosted Repositiry建立一个本机仓库,填入仓库相应的信息便可建立成功。
四、配置私服信息
和本地仓库同样,私服仓库也须要在setting.xml中进行配置,这样才可以访问。
在setting.xml 文件中找到<profiles></profiles>标签,在其中插入以下代码,其中的id,name标签内的内容必需要和在nexus中建立仓库是所填的仓库ID和仓库名称一致,URL标签内的内容就是该仓库建立后后面显示的地址。
<profile> <id>localRepository</id> <repositories> <repository> <id>myRepository</id> <name>myRepository</name> <url>http://127.0.0.1:8081/nexus/content/repositories/myRepository/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile>
而后还必需要激活改配置,在setting.xml文件的<activeProfiles></activeProfiles>标签内插入以下代码段。
<activeProfile>localRepository</activeProfile>
配置分发构建到私服的验证,在setting.xml文件的<servers></servers>标签内插入以下代码段
<server> <id>myRepo</id> <username>admin</username> <password>admin123</password> </server>
至此私服仓库就配置成功了。
3 中央仓库的配置
配置中央仓库和配置私服仓库相似:
一、在setting.xml 文件中找到<profiles></profiles>标签,在其中插入以下代码,其中的id,name标签内的内容必需要和在nexus中建立仓库是所填的仓库ID和仓库名称一致,URL标签内的内容就是该仓库建立后后面显示的地址。
<profile> <id>central</id> <repositories> <repository> <id>Central</id> <name>Central</name> <url>http://repo1.maven.org/maven2/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile>
二、而后还必需要激活改配置,在setting.xml文件的<activeProfiles></activeProfiles>标签内插入以下代码段。
<activeProfile>central</activeProfile>
4 三个仓库之间的关系
三者之间的关系是,当咱们在项目中依赖一个jar包时,Maven程序会先去本地仓库中找,若是没找到就回去私服找,若是仍是没有,最后就回去中央仓库找。其过程以下图: