我想分享我通过代理使用maven的经验.
您很可能会遇到异常和消息,例如:
repository metadata for: 'org.apache.maven.plugins' could not be retrieved from repository: central due to an error: Error transferring file: Connection refused: connect
要么
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean- plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5
如何配置Maven使用代理服务器?
Ric*_*ler 141
有关为Maven设置代理的详细信息,请参阅迷你指南.
基本上,您需要确保全局设置([maven install]/conf/settings.xml)或用户设置(${user.home}/.m2/settings.xml)中的代理部分配置正确.最好在用户设置中执行此操作,以避免将密码以纯文本格式存储在公共位置.
Maven 2.1引入了密码加密,但是我还没有检查加密是否适用于代理设置以及存储库密码(不明白为什么它不会).
有关信息,settings.xml中有一个注释掉的代理配置以及如何修改它的说明.
从迷你指南中,您的设置应如下所示:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
[...]
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>proxy.somewhere.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>somepassword</password>
<nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
</proxy>
</proxies>
[...]
</settings>
Run Code Online (Sandbox Code Playgroud)
小智 42
在某处设置到服务器的SSH隧道:
ssh -D $PORT $USER@$SERVER
Run Code Online (Sandbox Code Playgroud)
Linux(bash):
export MAVEN_OPTS="-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=$PORT"
Run Code Online (Sandbox Code Playgroud)
视窗:
set MAVEN_OPTS="-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=$PORT"
Run Code Online (Sandbox Code Playgroud)
kro*_*old 26
另请注意,一些插件(远程资源可以想到)使用一个非常老的库,它只接受通过MAVEN_OPTS的代理配置;
-Dhttp.proxyHost=<host> -Dhttp.proxyPort=<port> -Dhttps.proxyHost=<host> -Dhttps.proxyPort=<port>
Run Code Online (Sandbox Code Playgroud)
你可能会被困在auth上.
ped*_*isp 25
我也有这个问题,我通过编辑.m2文件夹中的settings.xml文件解决了这个问题.我的settings.xml现在是这样的:
<settings>
<proxies>
<proxy>
<id>genproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxyHost</host>
<port>3128</port>
<username>username</username>
<password>password</password>
</proxy>
</proxies>
</settings>
Run Code Online (Sandbox Code Playgroud)
Sar*_*dra 22
要设置Maven代理:
编辑〜/ .m2/settings.xml文件中的代理会话.如果找不到该文件,请创建一个.
<settings>
<proxies>
<proxy>
<id>httpproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>your-proxy-host</host>
<port>your-proxy-port</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
<proxy>
<id>httpsproxy</id>
<active>true</active>
<protocol>https</protocol>
<host>your-proxy-host</host>
<port>your-proxy-port</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
</settings>
Run Code Online (Sandbox Code Playgroud)
要么
编辑{M2_HOME} /conf/settings.xml中的代理会话
希望能帮助到你.. :)
Bog*_*dan 15
这些是由两个问题造成的:
如果省略其中一些 - maven可能会失败并显示随机错误消息.
只是希望我已经拯救了一些人来搜索这个问题6个小时,就像我一样.
And*_*nes 14
只是为了添加我自己的经验:我公司的代理是 http://webproxy.intra.companyname.com:3128.要使maven通过此代理工作,设置必须与此完全相同
<settings>
<proxies>
<proxy>
<id>default</id>
<active>true</active>
<protocol>http</protocol>
<host>webproxy.intra.companyname.com</host>
<port>3128</port>
</proxy>
</proxies>
</settings>
Run Code Online (Sandbox Code Playgroud)
与其他一些代理配置文件不同,protocol这里描述了如何连接代理服务器,而不是代理哪种协议.http目标的一部分必须从主机名中拆分,否则它将无法工作.
use*_*363 10
谢谢@krosenvold.
如果设置文件更改不起作用,请在具有POM文件的命令提示符中尝试此操作.
mvn install -Dhttp.proxyHost=abcproxy -Dhttp.proxyPort=8080 -Dhttps.proxyHost=abcproxy -Dhttps.proxyPort=8080
Run Code Online (Sandbox Code Playgroud)
密码更改后,这对我有所帮助.
我在cntlm本地运行,配置了NTLMv2密码哈希以与公司代理进行身份验证,并使用
export MAVEN_OPTS="-DproxyHost=127.0.0.1 -DproxyPort=3128"
Run Code Online (Sandbox Code Playgroud)
使用来自的代理maven。当然,您使用的代理应该支持cntlm/ NTLMv2。
并添加到这个主题,这是我的经验下面...真奇怪和耗时,所以我认为值得添加.
我在尝试在Windows上构建portlet-bridge时遇到了类似的问题,导致以下错误:
Downloading: http://repo1.maven.org/maven2/org/apache/portals/bridges-pom/1.0/bridges-pom-1.0.pom [DEBUG] Reading resolution tracking file C:\Documents and Settings\myuser\.m2\repository\org\apache\portals\bridges-pom\1.0\bridges-pom-1.0.pom.lastUpdated [DEBUG] Writing resolution tracking file C:\Documents and Settings\myuser\.m2\repository\org\apache\portals\bridges-pom\1.0\bridges-pom-1.0.pom.lastUpdated [ERROR] The build could not read 1 project -> [Help 1] org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM: Could not transfer artifact org.apache.portals:bridges-pom:pom:1.0 from/to central (http://repo1.maven.org/maven2): Error transferring file: repo1.maven.org and 'parent.relativePath' points at wrong local POM @ line 23, column 11 ... [ERROR] The project org.apache.portals.bridges:portals-bridges-common:2.0 (H:\path_to_project\portals-bridges-common-2.0\pom.xml) has 1 error [ERROR] Non-resolvable parent POM: Could not transfer artifact org.apache.portals:bridges-pom:pom:1.0 from/to central (http://repo1.maven.org/maven2): Error transferring file: repo1.maven.org and 'parent.relativePath' points at wrong local POM @ line 23, column 11: Unknown host repo1.maven.org -> [Help 2] ... [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
我尝试了一些事情,经过一些冲浪:
试图将parent.relativePath设置为空,以便maven认为父级不是本地的.这是根据Hudson构建失败的 SO的建议:不可解析的父POM和在这个讨论论坛.这没有效果.
我还尝试确保我的settings.xml中明确列出了存储库,但这也没有效果.
然后我确保mvn被迫查找存储库,而不是依赖于它自己的历史,正如Sarthon在本博客中所讨论的那样.不幸的是,这也不是问题.
在一些绝望中,我重新访问了我的MAVEN_OPTS以确保我没有违反我的代理设置.这些都是正确的,尽管价值没有引用:
设置MAVEN_OPTS = -Dhttp.proxyHost = myproxy.mycompany.com -Dhttp.proxyPort = 8080 -Xmx256m
所以,最后,我将代理配置移动到我的settings.xml中,这有效:
<proxies>
<proxy>
<id>genproxy</id>
<active>true</active>
<protocol>http</protocol>
<!--username>proxyuser</username-->
<!--password>proxypass</password-->
<host>myproxy.mycompany.com</host>
<port>8080</port>
<nonProxyHosts>*.mycompany.com|127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
Run Code Online (Sandbox Code Playgroud)
当settings.xml配置确实有效时,真的不确定为什么我的原始MAVEN_OPTS不起作用(引用?).我想扭转修复并再次检查每一步,但浪费了太多时间.将在何时报告.
如果您是 Maven 代理设置的新手,在我的情况下,首先检查您的主文件夹天气是否有.m2文件夹,其中应该有一个名为“settings.xml如果没有创建它”的文件,然后粘贴此文件并进行更改host,port然后如果需要,请更改nonProxyHosts
主文件夹 - C:\Users\ {UserName}
<settings>
<proxies>
<proxy>
<id>httpproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>your-proxy-host</host>
<port>your-proxy-port</port>
<nonProxyHosts>localhost</nonProxyHosts>
</proxy>
<proxy>
<id>httpsproxy</id>
<active>true</active>
<protocol>https</protocol>
<host>your-proxy-host</host>
<port>your-proxy-port</port>
<nonProxyHosts>localhost</nonProxyHosts>
</proxy>
</proxies>
</settings>
Run Code Online (Sandbox Code Playgroud)
如果在任何情况下都没有成功,请在主文件夹的此位置进行更改
/conf/settings.xml
Run Code Online (Sandbox Code Playgroud)
我正在使用 Eclipse 作为我的 IDE
希望这会有所帮助!
注意:要删除代理,只需移至settings.xml其他位置即可
| 归档时间: |
|
| 查看次数: |
218249 次 |
| 最近记录: |