激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

香港云服务器
服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - 詳解maven配置多倉(cāng)庫(kù)的方法示例

詳解maven配置多倉(cāng)庫(kù)的方法示例

2020-08-25 00:45等你歸去來(lái) Java教程

這篇文章主要介紹了詳解maven配置多倉(cāng)庫(kù)的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

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

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

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

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

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

  原私有配置示例如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?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改掉就行了,如:

?
1
2
3
4
5
6
7
8
9
<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è)地址改回來(lái)就可以了,這可能是改動(dòng)最小的方法了。但是也很惱火的一種配置方式,因?yàn)槟阋粫r(shí)地記得切換(誰(shuí)有那閑心)!!!

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<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>

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

3. 按照最簡(jiǎn)單的方式,新增一個(gè)倉(cāng)庫(kù)地址,隨時(shí)切換。

  不用去添加mirror了,直接以u(píng)rl的形式,配置到reponsitory里即可,如下:

?
1
2
3
4
5
6
7
8
9
10
<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>
?
1
2
3
4
5
<activeProfiles>
   <activeProfile>nexus</activeProfile>
   <!-- 添加此屬性,以便激活repo1的配置 -->
   <activeProfile>repo1</activeProfile>
 </activeProfiles>

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

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

?
1
2
3
4
<activeProfiles>
  <!-- 放心,此處的 nexus 是多個(gè)倉(cāng)庫(kù)的配置 -->
  <activeProfile>nexus</activeProfile>
</activeProfiles>

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
<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è)完整的配置樣例參考

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?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>
  <!-- 賬號(hào)信息保留,私服使用 -->
  <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í),就會(huì)先嘗試使用該repo進(jìn)行拉取了
      可添加任意多個(gè)倉(cāng)庫(kù),但如果網(wǎng)絡(luò)不通,這樣會(huì)導(dǎo)致很長(zhǎng)時(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>
    <!-- 公司的配置保留,添加自定義的倉(cāng)庫(kù)即可 -->
      <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配置多倉(cāng)庫(kù)的方法示例

詳解maven配置多倉(cāng)庫(kù)的方法示例

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

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

原文鏈接:https://www.cnblogs.com/yougewe/p/7294265.html

延伸 · 閱讀

精彩推薦
533
主站蜘蛛池模板: 涩涩屋av | 在线看免费观看日本 | 7777在线视频免费播放 | 色综合久久久久久久久久久 | 精品一区二区三区免费 | 亚洲一级片免费观看 | 91嫩草丨国产丨精品入口 | 天天干天天碰 | 亚洲视频精选 | 高潮激情aaaaa免费看 | 日本一区二区三区高清不卡 | 亚洲一二区视频 | 一区二区三区四区免费 | 国产一区二区欧美 | 小视频在线看 | 欧美日韩专区国产精品 | 牛牛热这里只有精品 | 看免费的毛片 | 黄视频网站免费 | 久久草在线看 | 一级免费黄色免费片 | 国产成人精品网站 | 百分百出品 | 香蕉成人在线视频 | 成av人在线观看 | 色淫视频 | 91麻豆蜜桃一区二区三区 | 午夜人体| 九九热视频免费观看 | 亚洲少妇诱惑 | 国产91丝袜在线熟 | 俄罗斯理伦片 | 国产pron | 久久不雅视频 | 国产二区三区在线播放 | 精品亚洲va在线va天堂资源站 | 91九色网址 | 午夜精品福利在线观看 | 欧美一级成人一区二区三区 | 国产一国产一级毛片视频在线 | 国产在线播放一区二区 |