Sunday Sep 01

How to configure Maven behind an auto configured proxy

PDF Print E-mail
Tuesday, 28 June 2011 12:28
AddThis Social Bookmark Button

Sometimes you are behind a proxy but you don't know the configuration details. You customer is using a Web Proxy Autodiscovery Protocol (aka WPAP).

In internet Explorer or Firefox you probably have the Automatic detects settings checked in your configuration. In the other hand you have Maven who wants to access the internet to download the plugins and libraries. In the following tutorial, i will give you a step by step tutorial to configure your Maven settings.xml file to use the proxy settings .

Retrieve the actual settings behind the Proxy Auto-Config (PAC)

Before fetching its first page, your favorite web browser implementing the auto configuration sends the local DHCP server a DHCPINFORM query, and uses the URL from the WPAD option in the server's reply. If the DHCP server does not provide the desired information, DNS is used.

If, for example, the network name of the user's computer is, the browser will try the following URLs in turn until it finds a proxy configuration file within the domain of the client:


After having downloaded this file you should see something like that inside :

wdap.dat sample proxy configuration

function FindProxyForURL(url, host) {
// If URL has no dots in host name, send traffic direct.
    if (isPlainHostName(host))
        return "DIRECT";
// If specific URL needs to bypass proxy, send traffic direct.
    if (shExpMatch(url,"**") ||
        return "DIRECT";
// If IP address is internal or hostname resolves to internal IP, send direct.
    var resolved_ip = dnsResolve(host);
    if (isInNet(resolved_ip, "", "") ||
        isInNet(resolved_ip, "",  "") ||
        isInNet(resolved_ip, "", "") ||
        isInNet(resolved_ip, "", ""))
        return "DIRECT";
// If not on a internal/LAN IP address, send traffic direct.
    if (!isInNet(myIpAddress(), "", ""))
        return "DIRECT";
// All other traffic uses below proxies, in fail-over order.
    return "PROXY; PROXY; DIRECT";

The most important information is the proxy information returned at line 21 :


You have two proxy addresses with there corresponding port. In our configuration example we will take those addresses to illustrate the maven configuration

Configure Maven according to the Automatic detects settings of your browser

You have know the primary and secondary proxy ip addresses and ports. We are know able to configure the proxy in our Maven settings.xml file.

Include the following snippet in the <proxies> section of your settings.xml-file:

proxy maven settings example


The <proxy> element contains informations required to a proxy settings.

Element Type Description
active boolean Whether this proxy configuration is the active one.
Default value is : true .
protocol String The proxy protocol.
Default value is : http .
username String The proxy user.
password String The proxy password.
port int The proxy port.
Default value is : 8080 .
host String The proxy host.
nonProxyHosts String The list of non-proxied hosts (delimited by |).
id String No description.
Default value is : default .

If your proxy requires a user name and password you can add it in the proxy section. The nonProxyHosts setting accepts wild cards, and each host not to proxy is separated by the | character. This matches the JDK configuration equivalent.

Source : Configuring a proxy

You are now able to download plugins and artifacts from your favorite repository.

If you have any remark or questions feel free to put a comment.If you enjoyed this tutorial and want to promote it don't hesitate to click on </p>

Tags: maven , http , configuration , password , configure , proxy , settings , string , nonproxyhosts

Add comment

Security code

Java Tutorial on Facebook