I want to share my experience of using maven through a proxy.
我想通过一个代理来分享我使用maven的经验。
You would most likely face exceptions and messages like:
你很可能会遇到这样的情况:
repository metadata for: 'org.apache.maven.plugins' could not be retrieved from repository: central due to an error: Error transferring file: Connection refused: connect
or
或
[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
How to configure Maven to use proxy server?
如何配置Maven来使用代理服务器?
13 个解决方案
#1
111
For details of setting up a proxy for Maven, see the mini guide.
有关设置Maven的代理的详细信息,请参阅“迷你指南”。
Essentially you need to ensure the proxies section in either the global settings ([maven install]/conf/settings.xml
), or user settings (${user.home}/.m2/settings.xml
) is configured correctly. It is better to do this in your user settings to avoid storing the password in plain text in a public location.
实际上,您需要确保在全局设置([maven安装]/conf/settings.xml)或用户设置(${user.home}/.m2/settings.xml)中正确配置了代理部分。最好在用户设置中这样做,以避免在公共场所的纯文本中存储密码。
Maven 2.1 introduced password encryption, but I've not got round to checking if the encryption applies for the proxy settings as well as repository passwords (don't see why it wouldn't though).
Maven 2.1引入了密码加密,但我还没有检查加密是否适用于代理设置和存储库密码(不知道为什么不这样做)。
For info, there is a commented-out proxy configuration in your settings.xml and instructions on how to modify it.
对于info,在您的设置中有一个经过注释的代理配置。xml和如何修改它的说明。
From the mini-guide, your settings should look something like this:
从迷你指南中,你的设置应该是这样的:
<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>
#2
36
如何使用socks代理?
Set up a SSH tunnel to a server somewhere:
设置SSH通道到服务器某处:
ssh -D $PORT $USER@$SERVER
Linux (bash):
Linux(bash):
export MAVEN_OPTS="-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=$PORT"
Windows:
窗口:
set MAVEN_OPTS="-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=$PORT"
#3
18
I also had this problem, and I solved it by editing the settings.xml file in my .m2 folder. My settings.xml is like this now:
我也有这个问题,我通过编辑设置来解决它。xml文件在我的。m2文件夹。我的设置。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>
#4
12
Also note that some plugins (remote-resources comes to mind) use a really old library that only accepts proxy configuration through MAVEN_OPTS;
还要注意的是,有些插件(远程资源)使用的是一个真正的旧库,它只通过MAVEN_OPTS接受代理配置;
-Dhttp.proxyHost=<host> -Dhttp.proxyPort=<port> -Dhttps.proxyHost=<host> -Dhttps.proxyPort=<port>
You might be stuck on auth for this one.
你可能会被困在这里。
#5
11
Those are caused most likely by 2 issues:
这些都是由两个问题引起的:
- You need to add proxy configuration to your settings.xml. Here's a trick in your username field. Make sure it looks like domain\username. Setting domain there and putting this exact slash is important '\'. You might want to use <![CDATA[]]> tag if your password contains non xml-friendly characters.
- 您需要将代理配置添加到您的settings.xml中。这是你的用户名字段中的一个技巧。确保它看起来像域\用户名。在那里设置定义域并将这个精确的斜杠设置为重要的“\”。您可能需要使用标签,如果您的密码包含非xml友好的字符。
- I've noticed maven 2.2.0 does not work sometimes through a proxy at all, where 2.2.1 works perfectly fine.
- 我注意到maven 2.2.0有时根本不通过代理来工作,在那里2.2.1工作得非常好。
If some of those are omitted - maven could fail with random error messages.
如果其中一些被省略了,maven可能会因为随机的错误消息而失败。
Just hope I've saved somebody from googling around this issue for 6 hours, like I did.
我希望我能像我一样,在这个问题上用谷歌搜索6个小时。
#6
9
Just to add my own experiences with this: my company's proxy is http://webproxy.intra.companyname.com:3128
. For maven to work via this proxy, the settings have to be exactly like this
我只是想补充一下我自己的经历:我公司的代理是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>
Unlike some other proxy-configuration files, the protocol
here describes how to connect to the proxy server, not which kinds of protocol should be proxied. The http
part of the target has to be split off from the hostname, else it won't work.
与其他一些代理配置文件不同,这里的协议描述了如何连接到代理服务器,而不是应该使用哪种协议。目标的http部分必须从主机名分离,否则它不会工作。
#7
7
To set Maven Proxy :
设置Maven代理:
Edit the proxies session in your ~/.m2/settings.xml file. If you cant find the file, create one.
在~/.m2/设置中编辑代理会话。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>
or
或
Edit the proxies session in your {M2_HOME}/conf/settings.xml
在您的{M2_HOME}/conf/settings.xml中编辑代理会话。
Hope it Helps.. :)
希望它能帮助. .:)
#8
6
And to add to this topic, here're my experiences below... Really odd and time consuming so I thought it was worth adding.
为了增加这个话题,下面是我的一些经验。真的很奇怪,很费时间,所以我觉得应该加上。
I've had a similar problem trying to built the portlet-bridge on Windows, getting the following errors:
我遇到过类似的问题,试图在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
I tried a couple of things, following a bit of surfing:
我尝试了几样东西,在冲浪之后:
-
Tried to set the parent.relativePath as empty so that maven didn't think the parent was local. This is as per the suggestion on SO at Hudson build fail: Non-resolvable parent POM and in this nabble forum. This had no effect.
试图设置父进程。相对路径为空,因此maven不认为父节点是本地的。这是根据在Hudson构建失败的建议:不可解析的父POM和在这个nabble论坛。这没有影响。
-
I also tried ensuring the repository was explicitly listed in my settings.xml but this had no effect either.
我还尝试确保在我的设置中明确列出了存储库。但这也没有效果。
-
I then ensured mvn was forced to lookup the repository, rather than rely on it's own history, as discussed in this blog by Sarthon. Unfortunately, this wasn't the issue either.
然后,我确保mvn*查找存储库,而不是依赖于它自己的历史,这是Sarthon在本博客中讨论的。不幸的是,这也不是问题所在。
-
In some desperation, I then revisited my MAVEN_OPTS to ensure I wasn't falling foul of my proxy settings. These were correct, albeit with the value unquoted:
在一些绝望中,我重新访问了我的MAVEN_OPTS,以确保我没有违反我的代理设置。这些都是正确的,尽管其价值未被引用:
set MAVEN_OPTS= -Dhttp.proxyHost=myproxy.mycompany.com -Dhttp.proxyPort=8080 -Xmx256m
设置MAVEN_OPTS -Dhttp = -Dhttp.proxyHost = myproxy.mycompany.com。proxyPort = 8080 -Xmx256m
-
So, finally, I moved the proxy config into my settings.xml and this worked:
最后,我将代理配置移动到我的设置中。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>
Really not sure why my original MAVEN_OPTS wasn't working (quotes?) while the settings.xml config did work. I'd like to reverse the fix and check each step again but have wasted too much time. Will report back as and when.
真的不知道为什么我最初的MAVEN_OPTS在设置时不起作用(引号?)xml配置工作。我想要倒车,检查每一步,但是浪费了太多时间。将会在何时返回。
#9
4
I know this is not really an answer to the question, but it might be worth knowing for someone searching this post. It is also possible to install a Maven repository proxy like nexus.
我知道这并不是一个真正的答案,但是对于搜索这个帖子的人来说,这可能是值得的。还可以安装Maven存储库代理(如nexus)。
Your maven would be configured to contact the local Nexus proxy, and Nexus would then retrieve (and cache) the artifacts. It can be configured through a web interface and has support for (http) proxies).
您的maven将被配置为联系本地的Nexus代理,然后Nexus将检索(并缓存)工件。它可以通过web接口进行配置,并支持(http)代理。
This can be an advantage, especially in a company setting, as artefacts are locally available and can be downloaded fast, and you are not that dependent on the availability of external Maven repositories anymore.
这可能是一个优势,特别是在公司设置中,因为artefacts是本地可用的,并且可以快速下载,而且您不再依赖外部Maven存储库的可用性。
To link back to the question; with Nexus there is a nice GUI for the proxy configuration, and it needs to be done on one place only, and not for every developer.
链接回到问题;对于代理配置来说,有一个很好的GUI,需要在一个地方完成,而不是每个开发人员。
#10
1
If maven works through proxy but not some of the plugins it is invoking, try setting JAVA_TOOL_OPTIONS
as well with -Dhttp*.proxy*
settings.
如果maven通过代理工作,而不是它所调用的一些插件,那么尝试设置JAVA_TOOL_OPTIONS和-Dhttp*。代理设置。
If you have already JAVA_OPTS
just do
如果您已经有JAVA_OPTS,那么就做吧。
export JAVA_TOOL_OPTIONS=$JAVA_OPTS
#11
1
Thanks @krosenvold.
谢谢@krosenvold。
If the settings file changes don't work, try this in the command prompt having the POM file.
如果设置文件更改不起作用,请在命令提示符中使用POM文件。
mvn install -Dhttp.proxyHost=abcproxy -Dhttp.proxyPort=8080 -Dhttps.proxyHost=abcproxy -Dhttps.proxyPort=8080
This has helped me immediately after a password change.
这帮我在密码修改后立即得到了帮助。
#12
0
Except for techniques mentioned above, with some effort, you can run maven through proxy using jproxyloader library (there is example on page how to do this: http://jproxyloader.sourceforge.net/). This allows set up socks proxy only for downloading artifacts.
除了上面提到的技术,通过一些努力,您可以使用jproxyloader库来运行maven(在页面上有一个示例:http://jproxyloader.sourceforge.net/)。这允许设置socks代理仅用于下载工件。
In solution mentioned by duanni (setting -DsocksProxyHost) there is one problem. If you have integration tests running against local database (or another tests connecting to url which should not go via proxy). These tests will stop working because connections to database will also be directed to proxy. With help of jProxyLoader you can set up proxy only for nexus host. Additionally if you want you can pass connections to database through another proxy.
在duanni提到的解决方案中(设置-DsocksProxyHost)有一个问题。如果您有针对本地数据库运行的集成测试(或者其他测试连接到不应该通过代理的url)。这些测试将停止工作,因为连接到数据库也将被定向到代理。在jProxyLoader的帮助下,您只能为nexus主机设置代理。另外,如果您希望您可以通过另一个代理传递到数据库的连接。
#13
0
The above postings helped in resolving my problem. In addition to the above I had to make the following changes to make it work :
上面的帖子帮助我解决了问题。除此之外,我还需要做以下的修改:
-
Modified Maven's JRE net settings(\jre\lib\net.properties) to use system proxy setting. https.proxyHost= proxy DNS https.proxyPort=proxy port
修改Maven的JRE网络设置(\ JRE \lib\net.properties)使用系统代理设置。https。proxyHost =代理DNS https。proxyPort =代理端口
- Included proxy server settings in settings.xml. I did not provide username and password settings as to use NTLM authentication.
- 在settings.xml中包含代理服务器设置。我没有提供使用NTLM身份验证的用户名和密码设置。
#1
111
For details of setting up a proxy for Maven, see the mini guide.
有关设置Maven的代理的详细信息,请参阅“迷你指南”。
Essentially you need to ensure the proxies section in either the global settings ([maven install]/conf/settings.xml
), or user settings (${user.home}/.m2/settings.xml
) is configured correctly. It is better to do this in your user settings to avoid storing the password in plain text in a public location.
实际上,您需要确保在全局设置([maven安装]/conf/settings.xml)或用户设置(${user.home}/.m2/settings.xml)中正确配置了代理部分。最好在用户设置中这样做,以避免在公共场所的纯文本中存储密码。
Maven 2.1 introduced password encryption, but I've not got round to checking if the encryption applies for the proxy settings as well as repository passwords (don't see why it wouldn't though).
Maven 2.1引入了密码加密,但我还没有检查加密是否适用于代理设置和存储库密码(不知道为什么不这样做)。
For info, there is a commented-out proxy configuration in your settings.xml and instructions on how to modify it.
对于info,在您的设置中有一个经过注释的代理配置。xml和如何修改它的说明。
From the mini-guide, your settings should look something like this:
从迷你指南中,你的设置应该是这样的:
<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>
#2
36
如何使用socks代理?
Set up a SSH tunnel to a server somewhere:
设置SSH通道到服务器某处:
ssh -D $PORT $USER@$SERVER
Linux (bash):
Linux(bash):
export MAVEN_OPTS="-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=$PORT"
Windows:
窗口:
set MAVEN_OPTS="-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=$PORT"
#3
18
I also had this problem, and I solved it by editing the settings.xml file in my .m2 folder. My settings.xml is like this now:
我也有这个问题,我通过编辑设置来解决它。xml文件在我的。m2文件夹。我的设置。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>
#4
12
Also note that some plugins (remote-resources comes to mind) use a really old library that only accepts proxy configuration through MAVEN_OPTS;
还要注意的是,有些插件(远程资源)使用的是一个真正的旧库,它只通过MAVEN_OPTS接受代理配置;
-Dhttp.proxyHost=<host> -Dhttp.proxyPort=<port> -Dhttps.proxyHost=<host> -Dhttps.proxyPort=<port>
You might be stuck on auth for this one.
你可能会被困在这里。
#5
11
Those are caused most likely by 2 issues:
这些都是由两个问题引起的:
- You need to add proxy configuration to your settings.xml. Here's a trick in your username field. Make sure it looks like domain\username. Setting domain there and putting this exact slash is important '\'. You might want to use <![CDATA[]]> tag if your password contains non xml-friendly characters.
- 您需要将代理配置添加到您的settings.xml中。这是你的用户名字段中的一个技巧。确保它看起来像域\用户名。在那里设置定义域并将这个精确的斜杠设置为重要的“\”。您可能需要使用标签,如果您的密码包含非xml友好的字符。
- I've noticed maven 2.2.0 does not work sometimes through a proxy at all, where 2.2.1 works perfectly fine.
- 我注意到maven 2.2.0有时根本不通过代理来工作,在那里2.2.1工作得非常好。
If some of those are omitted - maven could fail with random error messages.
如果其中一些被省略了,maven可能会因为随机的错误消息而失败。
Just hope I've saved somebody from googling around this issue for 6 hours, like I did.
我希望我能像我一样,在这个问题上用谷歌搜索6个小时。
#6
9
Just to add my own experiences with this: my company's proxy is http://webproxy.intra.companyname.com:3128
. For maven to work via this proxy, the settings have to be exactly like this
我只是想补充一下我自己的经历:我公司的代理是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>
Unlike some other proxy-configuration files, the protocol
here describes how to connect to the proxy server, not which kinds of protocol should be proxied. The http
part of the target has to be split off from the hostname, else it won't work.
与其他一些代理配置文件不同,这里的协议描述了如何连接到代理服务器,而不是应该使用哪种协议。目标的http部分必须从主机名分离,否则它不会工作。
#7
7
To set Maven Proxy :
设置Maven代理:
Edit the proxies session in your ~/.m2/settings.xml file. If you cant find the file, create one.
在~/.m2/设置中编辑代理会话。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>
or
或
Edit the proxies session in your {M2_HOME}/conf/settings.xml
在您的{M2_HOME}/conf/settings.xml中编辑代理会话。
Hope it Helps.. :)
希望它能帮助. .:)
#8
6
And to add to this topic, here're my experiences below... Really odd and time consuming so I thought it was worth adding.
为了增加这个话题,下面是我的一些经验。真的很奇怪,很费时间,所以我觉得应该加上。
I've had a similar problem trying to built the portlet-bridge on Windows, getting the following errors:
我遇到过类似的问题,试图在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
I tried a couple of things, following a bit of surfing:
我尝试了几样东西,在冲浪之后:
-
Tried to set the parent.relativePath as empty so that maven didn't think the parent was local. This is as per the suggestion on SO at Hudson build fail: Non-resolvable parent POM and in this nabble forum. This had no effect.
试图设置父进程。相对路径为空,因此maven不认为父节点是本地的。这是根据在Hudson构建失败的建议:不可解析的父POM和在这个nabble论坛。这没有影响。
-
I also tried ensuring the repository was explicitly listed in my settings.xml but this had no effect either.
我还尝试确保在我的设置中明确列出了存储库。但这也没有效果。
-
I then ensured mvn was forced to lookup the repository, rather than rely on it's own history, as discussed in this blog by Sarthon. Unfortunately, this wasn't the issue either.
然后,我确保mvn*查找存储库,而不是依赖于它自己的历史,这是Sarthon在本博客中讨论的。不幸的是,这也不是问题所在。
-
In some desperation, I then revisited my MAVEN_OPTS to ensure I wasn't falling foul of my proxy settings. These were correct, albeit with the value unquoted:
在一些绝望中,我重新访问了我的MAVEN_OPTS,以确保我没有违反我的代理设置。这些都是正确的,尽管其价值未被引用:
set MAVEN_OPTS= -Dhttp.proxyHost=myproxy.mycompany.com -Dhttp.proxyPort=8080 -Xmx256m
设置MAVEN_OPTS -Dhttp = -Dhttp.proxyHost = myproxy.mycompany.com。proxyPort = 8080 -Xmx256m
-
So, finally, I moved the proxy config into my settings.xml and this worked:
最后,我将代理配置移动到我的设置中。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>
Really not sure why my original MAVEN_OPTS wasn't working (quotes?) while the settings.xml config did work. I'd like to reverse the fix and check each step again but have wasted too much time. Will report back as and when.
真的不知道为什么我最初的MAVEN_OPTS在设置时不起作用(引号?)xml配置工作。我想要倒车,检查每一步,但是浪费了太多时间。将会在何时返回。
#9
4
I know this is not really an answer to the question, but it might be worth knowing for someone searching this post. It is also possible to install a Maven repository proxy like nexus.
我知道这并不是一个真正的答案,但是对于搜索这个帖子的人来说,这可能是值得的。还可以安装Maven存储库代理(如nexus)。
Your maven would be configured to contact the local Nexus proxy, and Nexus would then retrieve (and cache) the artifacts. It can be configured through a web interface and has support for (http) proxies).
您的maven将被配置为联系本地的Nexus代理,然后Nexus将检索(并缓存)工件。它可以通过web接口进行配置,并支持(http)代理。
This can be an advantage, especially in a company setting, as artefacts are locally available and can be downloaded fast, and you are not that dependent on the availability of external Maven repositories anymore.
这可能是一个优势,特别是在公司设置中,因为artefacts是本地可用的,并且可以快速下载,而且您不再依赖外部Maven存储库的可用性。
To link back to the question; with Nexus there is a nice GUI for the proxy configuration, and it needs to be done on one place only, and not for every developer.
链接回到问题;对于代理配置来说,有一个很好的GUI,需要在一个地方完成,而不是每个开发人员。
#10
1
If maven works through proxy but not some of the plugins it is invoking, try setting JAVA_TOOL_OPTIONS
as well with -Dhttp*.proxy*
settings.
如果maven通过代理工作,而不是它所调用的一些插件,那么尝试设置JAVA_TOOL_OPTIONS和-Dhttp*。代理设置。
If you have already JAVA_OPTS
just do
如果您已经有JAVA_OPTS,那么就做吧。
export JAVA_TOOL_OPTIONS=$JAVA_OPTS
#11
1
Thanks @krosenvold.
谢谢@krosenvold。
If the settings file changes don't work, try this in the command prompt having the POM file.
如果设置文件更改不起作用,请在命令提示符中使用POM文件。
mvn install -Dhttp.proxyHost=abcproxy -Dhttp.proxyPort=8080 -Dhttps.proxyHost=abcproxy -Dhttps.proxyPort=8080
This has helped me immediately after a password change.
这帮我在密码修改后立即得到了帮助。
#12
0
Except for techniques mentioned above, with some effort, you can run maven through proxy using jproxyloader library (there is example on page how to do this: http://jproxyloader.sourceforge.net/). This allows set up socks proxy only for downloading artifacts.
除了上面提到的技术,通过一些努力,您可以使用jproxyloader库来运行maven(在页面上有一个示例:http://jproxyloader.sourceforge.net/)。这允许设置socks代理仅用于下载工件。
In solution mentioned by duanni (setting -DsocksProxyHost) there is one problem. If you have integration tests running against local database (or another tests connecting to url which should not go via proxy). These tests will stop working because connections to database will also be directed to proxy. With help of jProxyLoader you can set up proxy only for nexus host. Additionally if you want you can pass connections to database through another proxy.
在duanni提到的解决方案中(设置-DsocksProxyHost)有一个问题。如果您有针对本地数据库运行的集成测试(或者其他测试连接到不应该通过代理的url)。这些测试将停止工作,因为连接到数据库也将被定向到代理。在jProxyLoader的帮助下,您只能为nexus主机设置代理。另外,如果您希望您可以通过另一个代理传递到数据库的连接。
#13
0
The above postings helped in resolving my problem. In addition to the above I had to make the following changes to make it work :
上面的帖子帮助我解决了问题。除此之外,我还需要做以下的修改:
-
Modified Maven's JRE net settings(\jre\lib\net.properties) to use system proxy setting. https.proxyHost= proxy DNS https.proxyPort=proxy port
修改Maven的JRE网络设置(\ JRE \lib\net.properties)使用系统代理设置。https。proxyHost =代理DNS https。proxyPort =代理端口
- Included proxy server settings in settings.xml. I did not provide username and password settings as to use NTLM authentication.
- 在settings.xml中包含代理服务器设置。我没有提供使用NTLM身份验证的用户名和密码设置。