快速搭建MAVEN私服


环境:windows64位

1.下载nexus运行包
https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/oss/nexus-2.14.8-01-bundle.zip

2.解压
D:\nexus-2.14.8-01-bundle

会有两个文件夹
nexus-2.14.8-01  和  sonatype-work


3.配置环境变量
D:\nexus-2.14.8-01-bundle\nexus-2.14.8-01\bin


4.安装nexus服务
nexus install


5.启动nexus服务
nexus start


6.访问地址,默认端口是8081
http://127.0.0.1:8081/nexus/

用户名密码,默认是:admin/admin123


7.服务安装好之后配置settings.xml文件 以下是我在工作中用到的完整配置
<?xml version="1.0" encoding="UTF-8"?>  
    <settingss xmlns="http://maven.apache.org/SETTINGS/1.0.0"  
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settingss-1.0.0.xsd">  
        
        <!--<localRepository>C:\Users\Administrator\.m2\repository</localRepository>-->
        <mirrors>  

            <mirror>     
              <id>releases</id>     
              <mirrorOf>*</mirrorOf>     
              <url>http://192.168.1.188:8081/nexus/content/groups/public</url>     
            </mirror>    
            <mirror>     
              <id>snapshots</id>     
              <mirrorOf>*</mirrorOf>     
              <url>http://192.168.1.188:8081/nexus/content/groups/public-snapshots</url>     
            </mirror>     
            <mirror>  
                <id>alimaven</id>  
                <name>aliyun maven</name>  
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
                <mirrorOf>central</mirrorOf>  
            </mirror>             
           <!--    
            <mirror>  
                <id>alimaven</id>  
                <name>aliyun maven</name>  
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
                <mirrorOf>central</mirrorOf>  
            </mirror>  
      
               <mirror>  
                <id>uk</id>  
                <mirrorOf>central</mirrorOf>  
                <name>Human Readable Name for this Mirror.</name>  
                <url>http://uk.maven.org/maven2/</url>  
            </mirror>  
      
            <mirror>  
                <id>CN</id>  
                <name>OSChina Central</name>  
                <url>http://maven.oschina.net/content/groups/public/</url>  
                <mirrorOf>central</mirrorOf>  
            </mirror>  
      
         mirror>  
                <id>nexus</id>  
                <name>internal nexus repository</name>  
                <url>http://192.168.1.100:8081/nexus/content/groups/public/</url>  
                <url>http://repo.maven.apache.org/maven2</url>  
                <mirrorOf>central</mirrorOf>  
            </mirror-->  
      
        </mirrors>

    <servers>
      <server>    
          <id>releases</id>    
          <username>admin</username>    
          <password>admin123</password>    
        </server>    
        <server>    
          <id>snapshots</id>    
          <username>admin</username>    
          <password>admin123</password>    
        </server>    
      </servers>

      <profiles>    
       <profile>    
          <id>nexus</id>    
          <repositories>    
            <repository>    
              <id>releases</id>    
              <url>http://nexus-releases</url>    
              <releases><enabled>true</enabled></releases>    
              <snapshots><enabled>true</enabled></snapshots>    
            </repository>    
            <repository>    
              <id>snapshots</id>    
              <url>http://nexus-snapshots</url>    
              <releases><enabled>true</enabled></releases>    
              <snapshots><enabled>true</enabled></snapshots>    
            </repository>    
          </repositories>    
          <pluginRepositories>    
             <pluginRepository>    
                    <id>releases</id>    
                     <url>http://nexus-releases</url>    
                     <releases><enabled>true</enabled></releases>    
                     <snapshots><enabled>true</enabled></snapshots>    
                   </pluginRepository>    
                   <pluginRepository>    
                     <id>snapshots</id>    
                      <url>http://nexus-snapshots</url>    
                    <releases><enabled>true</enabled></releases>    
                     <snapshots><enabled>true</enabled></snapshots>    
                 </pluginRepository>    
             </pluginRepositories>    
        </profile>    
      </profiles>
    <activeProfiles>    
      <activeProfile>nexus</activeProfile>    
    </activeProfiles>
 
</settingss>  


8.配置项目pom.xml文件,在pom文件中添加如下配置 ,注意<id>releases</id>和<id>snapshots</id> 需要和settings.xml文件中的id一致

    <distributionManagement>  
            <repository>  
                <id>releases</id>  
                <name>User Project Release</name>  
                <url>http://192.168.1.188:8081/nexus/content/repositories/releases/</url>  
            </repository>  
      
            <snapshotRepository>  
                <id>snapshots</id>  
                <name>User Project SNAPSHOTS</name>  
                <url>http://192.168.1.188:8081/nexus/content/repositories/snapshots/</url>  
            </snapshotRepository>  
        </distributionManagement>  

9.关联settings.xml文件本人用myeclipse ,选择Window->Preferences->输入maven->选择User Settings设置上面配置的settings文件

10.所有的配置基本配置完成
运行项目会从代理仓库下载jar包到私服仓库,再从私服下载到本地

11.仓库类型
hosted:本地仓库,通常我们会部署自己的构件到这一类型的仓库。比如公司的第二方库。
proxy:代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库。
group:仓库组,用来合并多个hosted/proxy仓库。

hosted一般可以分为
3rd party:一般用于上传三方的jar包
Releases:公司项目的发行版本
Snapshots:公司项目的快照版本,也就是临时版本

12.
使用deploy命令发布版本

deploy可能会出现401错误,权限问题
 1.确保第8条中仓库id和settings.xml中仓库id一致
 2.需要给admin用户deploy命令授权

maven私服安装的时候已经是系统服务了,随系统重启而重启

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值