Maven 3 behind a proxy

Maven 3 behind a proxy

By David WORMS

Jul 11, 2013

Categories: Hack | Tags: Maven, Java, 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:

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

Canada - Morocco - France

International locations

10 rue de la Kasbah
2393 Rabbat
Canada

We are a team of Open Source enthusiasts doing consulting in Big Data, Cloud, DevOps, Data Engineering, Data Science…

We provide our customers with accurate insights on how to leverage technologies to convert their use cases to projects in production, how to reduce their costs and increase the time to market.

If you enjoy reading our publications and have an interest in what we do, contact us and we will be thrilled to cooperate with you.