最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解maven配置多倉庫的方法示例

 更新時(shí)間:2020年08月24日 14:33:41   作者:等你歸去來  
這篇文章主要介紹了詳解maven配置多倉庫的方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

  剛接觸maven就是在公司里配置好的,所以一直以來使用都沒毛病,所以一直沒有去動(dòng)這些固有的東西。

  但是,后來把公司的電腦拿回家之后,發(fā)現(xiàn)有的東西就搞不起來了。原因也看一下就明白了,因?yàn)樵诠镜臅r(shí)候用的是公司的maven私服,所以回家后,用不了也是正常。

  但是,真的脫離了公司,自己就不能工作了嗎?不可能吧。 難道一下開源工具都必須要依賴于公司的網(wǎng)絡(luò)? 這明顯是不合理的。

  那么,就扯出本次文章的意義了,在家里,自然是要公有的maven倉庫了,那么,怎樣配置maven倉庫才能讓自己用起來順心呢?

1. 改掉原有的maven倉庫地址,讓maven從公網(wǎng)上摘取jar包下載,方便、快捷。

  原私有配置示例如下:

<?xml version="1.0" encoding="UTF-8"?> 
<settings 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/settings-1.0.0.xsd"> 
   <!-- localRepository  
    | The path to the local repository maven will use to store artifacts. 
    | 
    | Default: ${user.home}/.m2/repository --> 
   <localRepository>${user.home}/.m2/repository</localRepository> 
   <!--pluginGroups></pluginGroups-->  
   <!--proxies></proxies--> 
   <servers> 
    <server> 
      <id>releases</id> 
      <username>admin</username> 
      <password>123</password> 
    </server> 
    <server> 
      <id>snapshots</id> 
      <username>admin</username> 
      <password>123</password> 
    </server>   
   </servers> 
   <pluginRepositories>
    <pluginRepository>
      <id>mypublic</id>
      <name>Public</name>
      <url>http://test.nexus.com/nexus/content/groups/public/</url>
    </pluginRepository>
   </pluginRepositories>
   <mirrors> 
    <mirror>  
      <id>central</id>  
      <name>internal</name>  
      <url>http://test.nexus.com/nexus/content/groups/public/</url>  
      <mirrorOf>central</mirrorOf> 
    </mirror> 
   </mirrors> 
  <profiles> 
    <profile> 
       <id>nexus</id> 
       <!--Enable snapshots for the built in central repo to direct --> 
       <!--all requests to nexus via the mirror --> 
       <repositories> 
        <repository> 
          <id>central</id> 
          <url>http://central</url> 
          <releases><enabled>true</enabled></releases> 
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </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> 
  </profiles> 
 <activeProfiles> 
  <!--make the profile active all the time --> 
  <activeProfile>nexus</activeProfile> 
 </activeProfiles> 
</settings>

  如果想直接把私有的地方干掉,那么,這是最快的,直接把mirror的url改掉就行了,如:

<mirrors> 
    <mirror>  
      <id>central</id>  
      <name>internal</name>
       <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
       <!-- <url>http://test.nexus.com/nexus/content/groups/public/</url> -->  
      <mirrorOf>central</mirrorOf> 
    </mirror> 
   </mirrors>

  當(dāng)然了,到需要的地方,再把這個(gè)地址改回來就可以了,這可能是改動(dòng)最小的方法了。但是也很惱火的一種配置方式,因?yàn)槟阋粫r(shí)地記得切換(誰有那閑心)?。?!

2. 添加一個(gè)類似結(jié)構(gòu)的倉庫配置,這樣的話就不切來切去的了,一勞永逸。

  相當(dāng)于添加了多倉庫,如下:

<mirrors>
  <!-- 再添加一個(gè)mirror, 注意mirrorsOf 為 * -->
  <mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>*</mirrorOf>
  </mirror>    
</mirrors> 

<repositories>
  <!-- 添加一個(gè) repository -->
  <repository> 
    <id>alimaven</id> 
    <url>http://alimaven</url> 
    <releases><enabled>true</enabled></releases> 
    <snapshots>
      <enabled>true</enabled>
      <updatePolicy>always</updatePolicy>
    </snapshots> 
  </repository>
</repositories>

  這樣的話,就不用再切換了。但是,這會導(dǎo)致一種情況,在某環(huán)境不可用時(shí),maven下載jar將會很慢,嚴(yán)重影響心情,所以,其實(shí)是不建議這么干的。

3. 按照最簡單的方式,新增一個(gè)倉庫地址,隨時(shí)切換。

  不用去添加mirror了,直接以url的形式,配置到reponsitory里即可,如下:

<repository>  
  <!-- 直接添加一個(gè) repository,在 activeProfiles 里加上此id 即可 -->
  <id>repo1</id>  
  <name>org.maven.repo1</name>  
  <layout>default</layout> 
  <url>https://repo1.maven.org/</url>  
  <snapshots>  
    <enabled>false</enabled>  
  </snapshots>  
</repository>
<activeProfiles>
   <activeProfile>nexus</activeProfile>
   <!-- 添加此屬性,以便激活repo1的配置 -->
   <activeProfile>repo1</activeProfile>
 </activeProfiles>

  這樣,既不影響原來的結(jié)構(gòu),也不影響現(xiàn)在使用,在家的時(shí)候,可以將私有倉庫注釋掉,以提高訪問速度。

  注意: 最后一個(gè) activeProfiles 的屬性是必須的,否則你可能發(fā)現(xiàn)你改了配置,然而并沒有什么卵用!

<activeProfiles>
  <!-- 放心,此處的 nexus 是多個(gè)倉庫的配置 -->
  <activeProfile>nexus</activeProfile>
</activeProfiles>

4. 無法拉取包的困惑?你可能發(fā)現(xiàn),你的maven無法拉取 SNAPSHOT 包,然而包明明就在那里!

  是的,出于安全的考慮,maven 默認(rèn)是不會去使用 snapshot 包的,所以,如果你有需要使用 snapshot 包(很多公司可能大量使用),那么你就需要配置 SNAPSHOT 為允許了!

<repository>
     <id>central</id>
     <url>http://central</url>
     <releases>
        <enabled>true</enabled>
     </releases>
     <!-- 如下開啟 snapshots 功能 -->
     <snapshots>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
     </snapshots>
  </repository>

5.一個(gè)完整的配置樣例參考

  前面說的基本是從解決問題的思路去講解,可能還是不夠形象,或者每個(gè)人的理解總是有些差異,下面來一個(gè)完整的配置參考。你可以在這上面繼續(xù)任意發(fā)揮:

<?xml version="1.0" encoding="UTF-8"?>

<settings 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/settings-1.0.0.xsd">
 <localRepository>${user.home}/.m2/repository</localRepository>
 <servers>
  <!-- 賬號信息保留,私服使用 -->
  <server>
    <id>sec@public-snapshots</id>
    <username>snapshot_user</username>
    <password>snapshot123</password>
  </server>
  <server>
    <id>mirror-sec</id>
    <username>snapshot_user</username>
    <password>snapshot123</password>
  </server>
 </servers>

 <!-- 注釋掉該mirror 配置項(xiàng) -->
 <!-- <mirrors>
  <mirror>
   <id>mirror-sec</id>
   <mirrorOf>sec@public-snapshots,mirror-sec</mirrorOf>
   <url>http://maven.sec-ins.com.cn/repository/maven-public/</url>
  </mirror>
 </mirrors>
 -->
 
 
 <profiles>
  <profile>
   <id>sec</id>
   <!-- 注釋掉該默認(rèn)激活,統(tǒng)一在 activeProfiles 中配置-->
   <!-- <activation>
     <activeByDefault>true</activeByDefault>
   </activation> -->
   
   <repositories> 
    <!-- 直接添加一個(gè) repository, 運(yùn)行maven更新時(shí),就會先嘗試使用該repo進(jìn)行拉取了
      可添加任意多個(gè)倉庫,但如果網(wǎng)絡(luò)不通,這樣會導(dǎo)致很長時(shí)間的切換重試,可在ide中查看maven正在嘗試哪個(gè)repository
    --> 
    <repository>  
      <id>repo1</id>  
      <name>org.maven.repo1</name>  
      <layout>default</layout> 
      <url>https://repo1.maven.org/</url>
      <!-- <url>http://maven.aliyun.com/nexus/content/groups/public</url> -->  
      <snapshots>  
        <enabled>false</enabled>  
      </snapshots>  
    </repository>
    <!-- 公司的配置保留,添加自定義的倉庫即可 -->
      <repository> 
      <id>sec@public-snapshots</id> 
      <name>sec-snapshots</name> 
      <url>http://maven.sec-ins.com.cn/repository/maven-public</url> 
      <releases>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
        <checksumPolicy>warn</checksumPolicy>
      </releases> 
      <snapshots>
        <enabled>true</enabled>
      </snapshots> 
    </repository>
   </repositories>
   </profile>
   <!-- 注釋掉該plugin 配置 -->
   <!-- <pluginRepositories> 
    <pluginRepository> 
      <id>sec@public-snapshots</id> 
      <name>sec_plugin</name> 
      <url>http://maven.sec-ins.com.cn/repository/maven-public</url> 
      <releases>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
        <checksumPolicy>warn</checksumPolicy>
      </releases> 
      <snapshots>
        <enabled>true</enabled>
      </snapshots> 
    </pluginRepository>    
    </pluginRepositories>
    -->
  <!-- 你也可以另開一個(gè) profile, 保存自定義的 repositories, 在 activeProfiles 里加上此id 即可遍歷以下 repository -->
  <profile>
   <id>my-profile</id>
   <repositories>  
    <repository>
      <id>alirepo1</id>  
      <name>org.maven.repo1</name>  
      <layout>default</layout> 
      <!-- <url>https://repo1.maven.org/</url> -->
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
      <snapshots>  
        <enabled>false</enabled>  
      </snapshots>  
    </repository>
    
    <repository>
      <id>spring-milestones</id>
      <name>Spring Milestones</name>
      <url>https://repo.spring.io/milestone</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
    <repository>
      <id>repository.springframework.maven.release</id>
      <name>Spring Framework Maven Release Repository</name>
      <url>http://maven.springframework.org/milestone/</url>
    </repository>
    <repository>
      <id>org.springframework</id>
      <url> http://maven.springframework.org/snapshot</url>
    </repository>
    <repository>
      <id>spring-milestone</id>
      <name>Spring Maven MILESTONE Repository</name>
      <url>http://repo.spring.io/libs-milestone</url>
    </repository>
    <repository>
      <id>spring-release</id>
      <name>Spring Maven RELEASE Repository</name>
      <url>http://repo.spring.io/libs-release</url>
    </repository>
   </repositories>
   </profile>
 </profiles>

 <activeProfiles>
  <!-- 添加此屬性,需要激活自定義的repo 的profile配置 -->
   <activeProfile>sec</activeProfile>
   <activeProfile>my-profile</activeProfile>
 </activeProfiles>
</settings>

6. 另附一個(gè)idea maven配置的方法

  maven作為基礎(chǔ)輔助工具,雖不需去深入的理解,也沒有高深的技巧,但是作為沒有處理過幾個(gè)相關(guān)問題的同學(xué),還是很有必要了解的。

到此這篇關(guān)于詳解maven配置多倉庫的方法示例的文章就介紹到這了,更多相關(guān)maven配置多倉庫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

甘洛县| 涪陵区| 静乐县| 临潭县| 永德县| 山东省| 松潘县| 新竹市| 阜康市| 清水河县| 来宾市| 湘阴县| 三亚市| 宜宾县| 贞丰县| 乐都县| 西畴县| 深圳市| 同德县| 涟水县| 常熟市| 那曲县| 柳河县| 濮阳县| 太保市| 临沭县| 板桥市| 辉南县| 海口市| 甘德县| 东平县| 衡南县| 宽甸| 龙游县| 青海省| 张家川| 涞水县| 五河县| 清远市| 仪陇县| 肃南|