How to configure Maven proxy settings on Windows

  • 12 September 2016
  • ADM

 

How to configure Maven proxy settings on Windows - images/logos/windows.jpg

 

After we successfully installed Maven on Windows it time to see the proxy settings you might need if you access the internet using a proxy server.

If you are getting an error like Malformed reply from SOCKS server then you definitely need to configure proxy settings for Maven.

You can add two types of settings:

  • global settings: use this settings if you are the only person that is using your computer with maven. The configuration file location is <installation folder>\conf\settings.xml. In our case c:\tools\apache-maven-3.3.9\conf\settings.xml
  • user settings: use this settings if your computer is used by multiple users. The configuration file location is <username folder>\.m2\settings.xml. In our case C:\Users\adm\.m2\settings.xml

It doesn't matter the location the configuration file will have the same structure:

<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
	https://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository/>
    <interactiveMode/>
	<usePluginRegistry/>
	<offline/>
	<pluginGroups/>
	<servers/>
	<mirrors/>
	<proxies/>
	<profiles/>
	<activeProfiles/>
</settings>

In this tutorial we are focusing only on proxies section.

The section should look like this:

 ...
  <proxies>
    <proxy>
      <id>default</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>$$PROXY_HOST$$</host>
	  <username>$$USERNAME$$</username>
	  <password>$$PASSWORD$$</password>
      <port>$$PORT$$</port>
      <nonProxyHosts>192.*|google.com</nonProxyHosts>
    </proxy>
  </proxies>
  ...

Replace $$PROXY_HOST$$, $$USERNAME$$, $$PASSWORD$$ and $$PORT$$ with your proxy settings. Using nonProxyHosts section you can add hosts that need to be accessed directly.

Additional to this you need to copy wagon-http-lightweight library in maven lib\ext folder. Our case c:\tools\apache-maven-3.3.9\lib\ext.

For Maven version 3.x download from here. For Maven version 2.x you need an older version.

Congratulation you have successfully configured proxy for Maven.