如果你的公司正在建立一個防火牆,並使用HTTP代理伺服器來阻止用戶直接連接到互聯網。如果您使用代理,Maven將無法下載任何依賴。
為了使它工作,你必須聲明在 Maven 的配置檔中設置代理伺服器:settings.xml.
1. Maven配置檔
找到檔 {M2_HOME}/conf/settings.xml, 並把你的代理伺服器資訊配置寫入。注:{M2_HOME} => D:\software\xuhuhu.com\apache-maven
{M2_HOME}/conf/settings.xml
<!-- 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
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>
取消注釋代理選項,填寫您的代理伺服器的詳細資訊。
<!-- 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>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>zaixian</username>
<password>password</password>
<host>proxy.xuhuhu.com</host>
<port>8888</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
2. 保存檔
完成後,Apache Maven 應該是能夠通過代理伺服器立即連接到Internet。
注意:重新啟動不是必需的。Maven 只是一個命令,當你調用它,它會再次讀取該檔。
上一篇:
Eclipse構建Maven專案
下一篇:
Maven本地資源庫
