参考视频教程http://tieba.baidu.com/p/2836671913
http://www.icoolxue.com/album/show/45 第九讲
或者:http://blog.163.com/benbenfafa_88/blog/static/6493016220130451915187/
1、 作用
如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而一个团队中的所有人都重复的从maven仓库下 载构件无疑加大了仓库的负载和浪费了外网带宽,如果网速慢的话,还会影响项目的进程。
假如连接不上外网的情况下,我们可以搭建属于自己的maven私服来存放公共构件,这样既节省了网络带宽也会加速项目搭建的进程,
2、Nexus下载
下载地址:http://www.sonatype.org/nexus/go
3、Nexus安装启动
1:下载zip后解压到D:\nexus-2.8.0-05 如下图所示:
2:设置环境变量
在系统path后加;D:\nexus-2.8.0-05\nexus-2.8.0-05\bin;
3:设置nexus中jdk位置
D:\nexus-2.8.0-05\nexus-2.8.0-05\bin\jsw\conf目录小,使用文本编辑器打开wrapper.conf文件添加jdk安装路径到java前面加上反斜杠
4:以管理员身份打开命令提示符
输入nexus,如有提示证明安装成功。使用nexus install 把nexus安装位windows服务。
使用nexus start 启动服务或者直接在系统 服务手工启动该服务。
注意:个人用的nexus2.8.0版本,使用jdk6 。无法启动服务。在nexus2.6.0版本开始只支持jdk7版本。
5:nexus服务启动成功后,浏览器中输入http://127.0.0.1:8081/nexus/ 即可打开nexus后台管理界面。
默认的用户名和密码:admin/admin123
8081为默认的端口号,要修改端口号可进入nexus-2.8.0-05\conf, 打开nexus.properties文件,修改application-port属性值就可以了
4、在POM文件中配置Nexus仓库(不建议这样)
在项目的pom.xml中添加如下代码:
- <repositories>
- <repository>
- <id>nexus</id>
- <name>my-nexus-repository</name>
- <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>nexus</id>
- <name>my-nexus-repository</name>
- <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </pluginRepository>
- </pluginRepositories>
在pom文件中配置只对当前项目有效,而实际开发中不可能在每个项目中重复配置信息。
5、在setting.xml文件中配置Nexus仓库1)maven提供了profile来配置仓库信息:
- <profiles>
- <profile>
- <id>myprofile</id>
- <repositories>
- <repository>
- <id>central</id>
- <url>http://central</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>central</id>
- <url>http://central</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </pluginRepository>
- </pluginRepositories>
- </profile>
- </profiles>
2) 激活profile
- <activeProfiles>
- <activeProfile>myprofile</activeProfile>
- </activeProfiles>
3)配置镜像
- <mirrors>
- <mirror>
- <id>nexus</id>
- <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
- <mirrorOf>*</mirrorOf>
- </mirror>
- </mirrors>
这里配置mirrorOf的值为*,代表maven的所有访问请求都会指向到Nexus仓库组。
5、执行部署