使用代理上网的情况下,如何在 cmd 下运行 mvn?
下载了 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
?
?