打开%m2_home%/bin/settings.xml,增加如下一段:
<proxies>
<!-- 使用代理上网 -->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>192.168.1.1</host>
<port>8081</port>
<nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
<!-- 使用代理上网 -->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>192.168.1.1</host>
<port>8081</port>
<nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
host、port、username、password不用说,nonProxyHosts就是例外地址。
如果bin下面没有settings.xml,手工新建一个,完整的setting.xml如下:
<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository />
<interactiveMode />
<usePluginRegistry />
<offline />
<pluginGroups />
<servers />
<proxies>
<!-- 使用代理上网 -->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>192.168.1.1</host>
<port>8081</port>
<nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
<profiles />
<activeProfiles />
</settings>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository />
<interactiveMode />
<usePluginRegistry />
<offline />
<pluginGroups />
<servers />
<proxies>
<!-- 使用代理上网 -->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>192.168.1.1</host>
<port>8081</port>
<nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
<profiles />
<activeProfiles />
</settings>
完成后保存,再往c:\document and setting\\.m2\下面复制一份即可。
配置Maven代理
本文介绍如何在Maven中配置代理服务器以实现网络访问。通过编辑%m2_home%/bin/settings.xml文件,添加代理设置来实现Maven项目的网络连接。文中详细说明了各参数的作用及配置方法。
2618

被折叠的 条评论
为什么被折叠?



