Maven私服搭建

一.下载和安装

      1. 下载(https://pan.baidu.com/s/1_Cx3oYwbsYXQ7TOPm_fIiQ,提取码o7vi)

      2. 1).下载完毕解压到无中文的目录下

           

          windows+r打开services.msc,可以看到私服已经在服务中了

           

           3).启动服务 nexus start

            

            4).访问服务

             

             

            

           5.私服的分类(了解即可)

           

二.上传jar包到私服

      1).在Maven中的settings.xml中配置nexus 的账号和密码(将下列代码直接粘贴到对应位置就行)

<!-- nexus 的账号和密码 -->
    <server>
        <id>releases</id>
        <username>admin</username>
        <password>admin123</password>
    </server>
    <server>
        <id>snapshots</id>
        <username>admin</username>
        <password>admin123</password>
    </server>

     

      2).在pom文件中上传的位置(将以下代码放入pom中即可)

<!-- nexus上传的位置 -->
 <distributionManagement>
  	<repository>
  		<id>releases</id>
	<url>http://localhost:8081/nexus/content/repositories/releases/</url>
  	</repository> 
  	<snapshotRepository>
  		<id>snapshots</id>
	<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
  	</snapshotRepository> 
  </distributionManagement>

      3).执行上传命令deploy

     4).查看上传

三.从私服下载

      1).在settings.xml中配置私服下载的位置(复制下面代码至settings.xml中)

<!--私服下载的位置-->
<profile>   
   <!--profile的id-->
   <id>dev</id>   
    <repositories>   
      <repository>  
		<!--仓库id,repositories可以配置多个仓库,保证id不重复-->
        <id>nexus</id>   
		<!--仓库地址,即nexus仓库组的地址-->
        <url>http://localhost:8081/nexus/content/groups/public/</url>   
		<!--是否下载releases构件-->
        <releases>   
          <enabled>true</enabled>   
        </releases>   
		<!--是否下载snapshots构件-->
        <snapshots>   
          <enabled>true</enabled>   
        </snapshots>   
      </repository>   
    </repositories>  
	 <pluginRepositories>  
    	<!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
        <pluginRepository>  
        	<!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
            <id>public</id>  
            <name>Public Repositories</name>  
            <url>http://localhost:8081/nexus/content/groups/public/</url>  
        </pluginRepository>  
    </pluginRepositories>  
  </profile>

      

      2).在settings.xml中配置激活哪一个私服下载的位置(复制下面代码至settings.xml中)

<!---激活下载的地址-->
    <activeProfiles>
      <!-- 激活下载地址的id -->
      <activeProfile>dev</activeProfile>
    </activeProfiles>

      3).最后在Maven执行一下更新操作即可自动下载