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>

前四步 maven私服已經搭建成功,后面步驟 是將 jar 上傳到 私服

五、在nexus中配置權限

  1.新建倉庫,便於管理

  

  2.在Nexus中新建權限

  

   

  3.添加角色,並給角色授予權限

  

  4.添加用戶,並給用戶授予角色

  

六、配置上傳到私服,在pom中:

<distributionManagement> 
    <repository> 
        <id>test-party</id> 
        <name>test-user</name> 
        <url>http://localhost:8081/nexus/content/repositories/test-party</url> 
    </repository> 
</distributionManagement>

  id 對應剛剛 新建的maven庫的id,url對應剛剛新建的maven庫的url,如下: 

  

 name對應剛剛新建的用戶名:test-user

七、在pom.xml的servers標簽中加上:

<server>
    <id>test-party</id>
  <username>test-user</username>
  <password>xbq</password>
</server>

八、執行deploy,發布到私服

  選中項目,run as -- maven build ... ,在Goals中輸入 deploy ,其他的不需要填寫,執行Run,當看到控制台上 出現 BUILD SUCCESS,則成功!

九、在nexus中查看是否發布上去

  

注意:更新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工程默認是jdk1.5,怎么換成jdk1.7呢?

  在profiles標簽中加入:

    <profile>   
        <id>jdk-1.7</id>   
        <activation>   
          <activeByDefault>true</activeByDefault>   
          <jdk>1.7</jdk>   
        </activation>   
        <properties>   
            <maven.compiler.source>1.7</maven.compiler.source>   
            <maven.compiler.target>1.7</maven.compiler.target>   
            <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>   
        </properties>   
    </profile>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM