Maven-Nexus私服搭建(四)

参考视频教程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中添加如下代码:

[html]  view plain copy
  1. <repositories>     
  2.     <repository>     
  3.       <id>nexus</id>     
  4.       <name>my-nexus-repository</name>     
  5.       <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>     
  6.       <releases>     
  7.         <enabled>true</enabled>     
  8.       </releases>     
  9.       <snapshots>     
  10.         <enabled>false</enabled>     
  11.       </snapshots>     
  12.     </repository>     
  13.   </repositories>     
  14.   <pluginRepositories>     
  15.     <pluginRepository>     
  16.       <id>nexus</id>     
  17.       <name>my-nexus-repository</name>     
  18.       <url>http://127.0.0.1:7788/nexus/content/groups/public/</url>     
  19.       <releases>     
  20.         <enabled>true</enabled>     
  21.       </releases>     
  22.       <snapshots>     
  23.         <enabled>false</enabled>     
  24.       </snapshots>          
  25.     </pluginRepository>     
  26.   </pluginRepositories>     

在pom文件中配置只对当前项目有效,而实际开发中不可能在每个项目中重复配置信息。

5、在setting.xml文件中配置Nexus仓库

1)maven提供了profile来配置仓库信息:

[html]  view plain copy
  1. <profiles>  
  2.     <profile>  
  3.       <id>myprofile</id>  
  4.       <repositories>  
  5.             <repository>  
  6.                 <id>central</id>                                     
  7.                 <url>http://central</url>                        
  8.                 <releases>  
  9.                     <enabled>true</enabled>  
  10.                 </releases>  
  11.                 <snapshots>  
  12.                     <enabled>true</enabled>  
  13.                 </snapshots>  
  14.             </repository>  
  15.         </repositories>     
  16.          <pluginRepositories>  
  17.             <pluginRepository>  
  18.               <id>central</id>  
  19.               <url>http://central</url>  
  20.               <releases>  
  21.                 <enabled>true</enabled>  
  22.               </releases>  
  23.               <snapshots>  
  24.                 <enabled>false</enabled>  
  25.               </snapshots>  
  26.             </pluginRepository>  
  27.         </pluginRepositories>  
  28.     </profile>  
  29. </profiles>  

2) 激活profile

[html]  view plain copy
  1. <activeProfiles>  
  2.     <activeProfile>myprofile</activeProfile>  
  3.   </activeProfiles>  

3)配置镜像

[html]  view plain copy
  1. <mirrors>  
  2.     <mirror>     
  3.      <id>nexus</id>      
  4.      <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>     
  5.      <mirrorOf>*</mirrorOf>     
  6.    </mirror>  
  7.  </mirrors>  

这里配置mirrorOf的值为*,代表maven的所有访问请求都会指向到Nexus仓库组。

5、执行部署


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值