背景:公司不允許直接訪問外部網(wǎng)絡(luò),需要經(jīng)過代理驗(yàn)證(比如在安全限制上設(shè)置了白名單網(wǎng)站),這時(shí),maven需要通過配置http代理訪問中央倉庫(repo1.maven.org)
工作環(huán)境:
操作系統(tǒng):mac os x
maven版本:3.3.9
步驟:
1、確認(rèn)是否可以直接訪問公共的maven中央倉庫
直接ping repo1.maven.org:
如果不能ping通,說明無法訪問,進(jìn)如下一步
如果可以ping通,則無需做任何配置可以直接訪問maven中央倉庫
2、編輯/Users/username/.m2/settings.xml(如果沒有該文件,復(fù)制$M2_HOME/conf/settings.xml,且.m2目錄是隱藏目錄,需要設(shè)置可見),添加代理配置
settings.xml位置示例
配置示例:
<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">
<!-- proxies | This is a list of proxies which can be used on this machine
to connect to the network. | Unless otherwise specified (by system property
or command-line switch), the first proxy | specification in this list marked
as active will be used. | -->
<proxies>
<proxy>
<id>workProxy</id>
<active>true</active>
<protocol>http</protocol>
<username>admin</username>
<password>admin</password>
<host>172.17.13.12</host>
<port>8088</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
</settings>
id:可選,可以配置多個(gè)代理節(jié)點(diǎn)(proxy)
active:true/false,true的話說明該代理配置激活使用
protocol:http,代理的協(xié)議,這里就是http
username:用戶名,代理需要賬號校驗(yàn)時(shí)填寫,否則注釋掉
password:密碼,代理需要賬號校驗(yàn)時(shí)填寫,否則注釋掉
host:代理ip
port:代理端口
nonProxyHosts:無需經(jīng)過代理訪問的網(wǎng)站,多個(gè)的話通過|隔開