首页 > 代码库 > Maven(二)-- 搭建私服,上传jar

Maven(二)-- 搭建私服,上传jar

一、在setting中配置 私服的镜像,在mirrors标签中加上:

<!--第一步  配置私服的镜像-->
<mirror>
     <!--此处配置所有的构建均从私有仓库中下载 *代表所有,也可以写central -->
     <id>nexus</id>
     <mirrorOf>*</mirrorOf>
     <!-- url对应发私服的 Public Repositories -->
     <url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>    

二、nexus工厂的配置,在profiles标签中加上:

<profile>
  <id>nexus</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>true</enabled></snapshots>
          </pluginRepository>
     </pluginRepositories>
</profile>

三、激活profile配置

<!--第三步  激活profile配置 -->
  <activeProfiles>
     <!--make the profile active all the time -->
     <activeProfile>nexus</activeProfile>
  </activeProfiles>

 四、在pom.xml中配置

<repositories>
     <repository>
         <id>central</id>
         <url>http://localhost:8081/nexus/content/groups/public/</url>
         <releases><enabled>true</enabled></releases>
         <snapshots><enabled>true</enabled></snapshots>
     </repository>
</repositories>
<pluginRepositories>
     <pluginRepository>
         <id>central</id>
         <url>http://localhost:8081/nexus/content/groups/public/</url>
         <releases><enabled>true</enabled></releases>
         <snapshots><enabled>true</enabled></snapshots>
      </pluginRepository>
 </pluginRepositories>

 五、配置上传到私服,在pom中:

<distributionManagement> 
    <repository> 
        <id>releases</id> 
        <name>Internal Releases</name> 
        <url>http://localhost:8081/nexus/content/repositories/releases/</url> 
    </repository> 
</distributionManagement>

六、在nexus中配置权限

 

七、在pom.xml的servers标签中加上:

<server>
    <id>增加的maven库的id</id>
  <username>新建的名字</username>
  <password>pass</password>
</server>

 八、更新jar遇到错误:

  was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced

  解决办法:去自己的.m2 文件夹下把 xxx.lastUpdated 文件全部删掉,重新运行maven,ok!

 

  

 

Maven(二)-- 搭建私服,上传jar