一、安装maven
到apache网站上下载maven,解压到一个目录下,如:D:\java\apache-maven-3.0.5,然后配置配置环境变量,创建M2_HOME,值为D:\java\apache-maven-3.0.5,再将%M2_HOME%\bin加入到path中,这样maven就安装好了。然后在dos下输入mvn --version,会有如下信息
二、安装nexus服务器
到nexus网站上下载nexus,然后解压到一个目录,如:D:\java\nexus-latest-bundle,配置环境变量,创建NEXUS_HOME,值为D:\java\nexus-latest-bundle,然后将%NEXUS_HOME%\bin加入到path中,这样nexus就安装好了。在dos下输入nexus,如图
就说明安装好了,然后输入nexus install,就把nexus安装到系统服务里了,nexus start 就启动了nexus了,然后登陆nexus的首页:http://localhost:8081/nexus/index.html,右上角的login可以登陆,默认用户名是admin,密码是admin123。
三、搭建私服
1、配置maven根目录下的conf文件夹下的settings.xml,指定工厂的路径,找到<localRepository>这个节点,指定路径,如<localRepository>D:/Users/Administrator/AppData/Local/Maven/repository</localRepository>,没有文件夹的就要创建相应的文件夹,然后将settings.xml文件拷贝一份到D:/Users/Administrator/AppData/Local/Maven下,这样,工厂就指定好了。
2、配置访问私服的网址
指定镜像地址:找到<mirrors>节点,加入
<!--工厂的镜像,只要mirrorOf中的工厂要访问就会找镜像,如果镜像无法访问,就不会再找镜像-->
<mirror>
<id>nexusMirror</id>
<!--<mirrorOf>nexus, central</mirrorOf>-->
<!--"*"表示所有的访问都使用这个镜像访问,推荐使用-->
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
指定中央工厂和自定义工厂的访问网址:找到<profiles>节点,加入
<profile>
<id>nexusReposFile</id>
<repositories>
<repository>
<id>nexus</id>
<name>Nexus Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<!--snapshots默认是关闭的 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<!--中央工厂-->
<profile>
<id>centralReposFile</id>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<!--此url没有意义-->
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
然后激活指定的工厂:
<activeProfiles>
<!--只有激活后才会生效-->
<activeProfile>centralReposFile</activeProfile>
</activeProfiles>
这样,私服就配置成功了。