下載了 maven 工具,準備在 cmd 下使用 mvn 構建 maven 工程時,提示連接出錯。花了幾分鐘 bing 了一番(google 服務最近不穩定,發現 bing 是個不錯的替代品~ 對了,用 bing 的時候關鍵詞如果是英文,記得儘量使用英文搜索),最後還是 StackOverFlow [1] 上找到了答案。
解決方法很簡單,只需要修改 maven 路徑下的 conf/settings.xml 文件。
默認的 proxy 代理配置(apache-maven-2.2.1)如下:
<!-- 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>
修改應該簡單了,記得把註釋去掉!
---------------------------------------------------------------------------------
其實 Apache Maven guide [2] 下面有關於 proxy 的說明。。。
[1] http://stackoverflow.com/a/3603093
[2] Configuration guide.http://maven.apache.org/guides/mini/guide-proxies.html