Adaltas

Maven 3 behind a proxy

Maven 3 isn’t so different to it’s previous version 2. You will migrate most of your project quite easily between the two versions. That wasn’t the case a fews years ago between versions 1 and 2. However it took me some time to find out how to properly configure my proxy settings and this article is the occasion to share the result and keep it for later consultation.

I am not Maven stronger evengelist even if I started to use it in its infantery in version 1. That must have been in 2003 if I recall. Ever since, to be honest, I feel fear as soon as I realised there are no more alternative than opening Eclipse and configuring Maven. But hey, Hadoop is Java so like it or not, I have to deal with it. And if I could choose, I’ll rather use Maven than Ant.

I don’t remember exactly how this was done in Maven 2 but I think proxy were defined directly inside the “pom.xml” file. Maven 3 choose to externalize this configuration into a settings file. I place the file into “./conf/settings.xml” and I reference it when running my Maven command such as mvn -s ./conf/settings.xml jar:jar.

For an authenticated proxy, the content of my settings file is :

1
2
3
4
5
6
7
8
9
10
11
12
13
<settings>
  <proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>myproxydomain.com</host>
      <port>3128</port>
      <username>XXX</username>
      <password>YYY</password>
      <nonProxyHosts>localhost</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

Comments