tags:

views:

1592

answers:

4

Hi dear community,

I wanna share with you my experience of using maven through proxy.

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

See my answer below.

All the best. Thanks

+2  A: 

For details of setting up a proxy for Maven, see the mini guide.

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 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).

For info, there is a commented-out proxy configuration in your settings.xml and instructions on how to modify it.

From the mini-guide, your settings should look something like this:

<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>
Rich Seller
Thanks, but this post is rather a tip for others than a question.I have resolved this problem already, but spent too much time at non-obvious things. I posted this so that it might be useful for somebody.
Bogdan
A: 

Those are caused most likely by 2 issues:

  1. 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.
  2. I've noticed maven 2.2.0 does not work sometimes through a proxy at all, where 2.2.1 works perfectly fine.

If some of those are omitted - maven could fail with random error messages.

Just hope I've saved somebody from googling around this issue for 6 hours, like I did.

Bogdan
Are you using an NTLM proxy? from the mini guide: "Please note that [c]urrently NTLM proxies are not supported as they have not been tested. You may be able to use the relevant system properties on JDK 1.4+ to make this work."
Rich Seller
Not sure about this. That is a corporate proxy that's actually placed 600 miles from me and nobody from system administration is in office this weekend. So can't ask anybody now. It will be interesting to find out. I know it supports http, socks and other protocols. Maybe it's NTML as well.
Bogdan
+2  A: 

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.

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).

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.

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.

extraneon
A: 

I've set up a SOCKS5 proxy and I'd like maven to use it. However there seems to be no documentation available on how to do this. No example in settings.xml either. Is it possible?

reinouts
I think I found the solution for my problem. Add -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=7070 (for a SOCKS5 proxy on localhost port 7070, obviously) to the mvn command line seems to work!
reinouts