公司基于安全需要通过代理访问因特网,这种情况需要为maven配置HTTP代理
检查:
1、能否访问Maven中央仓库,可以访问中央仓库则不需代理
2、代理服务是否畅通
[root@localhost ~]# ping repo1.maven.org
PING sonatype.map.fastly.net (151.101.52.209) 56(84) bytes of data.
64 bytes from 151.101.52.209 (151.101.52.209): icmp_seq=1 ttl=128 time=366 ms
64 bytes from 151.101.52.209 (151.101.52.209): icmp_seq=2 ttl=128 time=327 ms
[root@localhost ~]# telnet 39.156.66.14 80
Trying 39.156.66.14...
Connected to 39.156.66.14.
Escape character is '^]'.
HTTP/1.1 400 Bad Request
配置
修改$M2_HOME/conf/setting.xml
<settings >
<proxies>
<proxy>
<id>my-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.host.net</host>
<port>80</port>
<username>proxyuser</username>
<password>proxypass</password>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
</settings>
声明一个id为my-proxy
的代理
active
为true表示激活该代理(proxy可以有多个)
protocol
、host
和port
是必须的
username
、password
,在代理服务器需要认证时填写
nonProxyHosts
用来指定哪些主机名不需要代理