How to configure Maven behind an auto configured proxy
|
|
|
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 station.department.branch.ubiteck.com, the browser will try the following URLs in turn until it finds a proxy configuration file within the domain of the client:
- http://wpad.department.branch.ubiteck.com/wpad.dat
- http://wpad.branch.ubiteck.com/wpad.dat
- http://wpad.ubiteck.com/wpad.dat
- http://wpad.com/wpad.dat
After having downloaded this file you should see something like that inside :
The most important information is the proxy information returned at line 21 :
return "PROXY 1.2.3.4:8080; PROXY 4.5.6.7:8080; DIRECT";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:
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