码迷,mamicode.com
首页 > 其他好文 > 详细

使用nexus搭建maven私服

时间:2017-06-09 23:31:45      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:地址   strong   encoding   set   项目部署   admin   全局   ini   color   

使用nexus搭建maven私服

国内访问maven仓库速度渣渣,公司访问外网速度不快,即使用阿里云镜像效果也不佳。在局域网内搭建Maven私服,除了能从私服加速下载jar包,还能将内部通用模块发布在私服上供其他同事使用。对内部项目部署很有帮助。

安装和启动nexus

下载nexus-2.14.2-01-bundle.tar.gz 
https://www.sonatype.com/download-oss-sonatype

# 添加用户
adduser nexus  
passwd nexus   
su nexus

cd /home
mkdir nexus
cd nexus
tar xvzf nexus-2.14.2-01-bundle.tar.gz
cd nexus-2.14.2-01/bin

#启动nexus
./nexus start

浏览器中输入http://127.0.0.1:8081/nexus/

nexus的maven仓库配置

开启远程索引

新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。登陆nexus系统,默认用户名密码为admin/admin123

  • 点击左边Administration菜单下面的Repositories,找到右边仓库列表中的Apache Snapshots,Central,然后在configuration下把Download Remote Indexes修改为true 
    技术分享
  • 仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件。 
    技术分享

这样设置以后, Nexus会自动从远程中央仓库下载索引文件, 为了检验索引文件自动下载是否生效,可以却换到Browse Index查看

增加阿里云镜像

Repositories –> Add –>ProxyRepository
阿里的maven镜像:
http://maven.aliyun.com/nexus/content/groups/public/
Checksum Policy 可以改为ignore

技术分享
Repositories –> Public Repositories 
将右侧栏全部加入左侧栏即可 
技术分享

项目maven配置

settings.xml的配置

原文地址:http://blog.csdn.net/liujiahan629629/article/details/39272321

[html] view plain copy
 
 print?
  1. <span style="font-size:18px;">1.    <?xml version="1.0" encoding="UTF-8"?>    
  2. 2.  <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"     
  3. 3.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
  4. 4.            xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">    
  5. 5.      
  6. 6.    <pluginGroups></pluginGroups>    
  7. 7.    <proxies></proxies>    
  8. 8.      
  9. 9.    <servers>    
  10. 10.       <server>    
  11. 11.       <id>nexus-releases</id>    
  12. 12.       <username>admin</username>    
  13. 13.       <password>admin123</password>    
  14. 14.     </server>    
  15. 15.     <server>    
  16. 16.       <id>nexus-snapshots</id>    
  17. 17.       <username>admin</username>    
  18. 18.       <password>admin123</password>    
  19. 19.     </server>    
  20. 20.   </servers>    
  21. 21.     
  22. 22.   <mirrors>     
  23. 23.     <mirror>     
  24. 24.       <id>nexus-releases</id>     
  25. 25.       <mirrorOf>*</mirrorOf>     
  26. 26.       <url>http://localhost:8081/nexus/content/groups/public</url>     
  27. 27.     </mirror>    
  28. 28.     <mirror>     
  29. 29.       <id>nexus-snapshots</id>     
  30. 30.       <mirrorOf>*</mirrorOf>     
  31. 31.       <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>     
  32. 32.     </mirror>     
  33. 33.   </mirrors>     
  34. 34.      
  35. 35.   <profiles>    
  36. 36.    <profile>    
  37. 37.       <id>nexus</id>    
  38. 38.       <repositories>    
  39. 39.         <repository>    
  40. 40.           <id>nexus-releases</id>    
  41. 41.           <url>http://nexus-releases</url>    
  42. 42.           <releases><enabled>true</enabled></releases>    
  43. 43.           <snapshots><enabled>true</enabled></snapshots>    
  44. 44.         </repository>    
  45. 45.         <repository>    
  46. 46.           <id>nexus-snapshots</id>    
  47. 47.           <url>http://nexus-snapshots</url>    
  48. 48.           <releases><enabled>true</enabled></releases>    
  49. 49.           <snapshots><enabled>true</enabled></snapshots>    
  50. 50.         </repository>    
  51. 51.       </repositories>    
  52. 52.       <pluginRepositories>    
  53. 53.          <pluginRepository>    
  54. 54.                 <id>nexus-releases</id>    
  55. 55.                  <url>http://nexus-releases</url>    
  56. 56.                  <releases><enabled>true</enabled></releases>    
  57. 57.                  <snapshots><enabled>true</enabled></snapshots>    
  58. 58.                </pluginRepository>    
  59. 59.                <pluginRepository>    
  60. 60.                  <id>nexus-snapshots</id>    
  61. 61.                   <url>http://nexus-snapshots</url>    
  62. 62.                 <releases><enabled>true</enabled></releases>    
  63. 63.                  <snapshots><enabled>true</enabled></snapshots>    
  64. 64.              </pluginRepository>    
  65. 65.          </pluginRepositories>    
  66. 66.     </profile>    
  67. 67.   </profiles>    
  68. 68.     
  69. 69.   <activeProfiles>    
  70. 70.       <activeProfile>nexus</activeProfile>    
  71. 71.   </activeProfiles>    
  72. 72.      
  73. 73. </settings>    
  74. </span>  

 

 

 

maven的全局配置文件

修改maven的settings.xml配置文件,如C:\Users\xieyue.m2\settings.xml

    <!--deploy发布项目到私服的用户密码-->
    <servers>
        <server>  
          <id>releases</id>  
          <username>deployment</username>  
          <password>xxx</password>  
        </server>  
        <server>  
          <id>snapshots</id>  
          <username>deployment</username>  
          <password>xxx</password>  
        </server>  
    </servers>

    <!--使用私服仓库-->
    <profiles>
        <profile>
            <repositories>  
                <repository>  
                    <id>nexus</id>  
                    <name>nexus</name>  
                    <url>http://132.97.8.177:8081/nexus/content/groups/public/</url>  
                    <releases>  
                        <enabled>true</enabled>  
                    </releases>  
                    <snapshots>  
                        <enabled>true</enabled>  
                    </snapshots>  
                </repository>  
            </repositories>  
        </profile>
     </profiles>

    <activeProfiles>
      <activeProfile>nexus</activeProfile>
    </activeProfiles>

项目的POM.xml设置

        <!-- mvn deploy的发布地址 -->
    <distributionManagement>
        <repository>
            <id>releases</id>
            <name>Internal Releases</name>
            <url>http://132.97.8.177:8081/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Internal Snapshots</name>
            <url>http://132.97.8.177:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>


    <!-- 使用本地maven私库 -->
    <repositories>  
        <repository>  
            <id>nexus</id>  
            <name>nexus</name>  
            <url>http://132.97.8.177:8081/nexus/content/groups/public/</url>  
            <releases>  
                <enabled>true</enabled>  
            </releases>  
            <snapshots>  
                <enabled>true</enabled>  
            </snapshots>  
        </repository>  
    </repositories> 

参考资料

http://books.sonatype.com/nexus-book/reference/installing.html
http://blog.csdn.net/ClementAD/article/details/52670968

使用nexus搭建maven私服

标签:地址   strong   encoding   set   项目部署   admin   全局   ini   color   

原文地址:http://www.cnblogs.com/linjiaxin/p/6973998.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!