In this article, we will explore and understand on how to configure/enable proxy setting in Maven
1. Proxy setting explanation:
- Sometimes, Maven users sit behind the firewall especially when developers work in a client network. In these scenarios, we need to tweak proxy setting or enable proxy setting in Maven’s settings.xml located at {MAVEN_HOME}\conf\settings.xml
- If this proxy setting is not enabled while working behind the firewall, then maven will fail to resolves dependencies (i.e.; connection refused to download any dependencies from internet)
- In these circumstances, it’s a wise advice to enable proxies by configuring required attributes
- Let’s understand how to configure mandatory values inside <proxy> element in settings.xml
1.1 Understand settings.xml file and find <proxy> element
<!-- proxies | This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used. | -->
<proxies>
<!-- proxy | Specification for one proxy, to be used in connecting to the
network. |
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy> -->
</proxies>
1.2 Un-comment the <proxy> element –> configure required attributes –> save file
- Protocol, username/password, host, port are self explanatory –> get these required values and configure it
- Note: Make sure to mark <active> element as “true”, if you are intended to work via this proxy
<!-- proxies | This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used. | -->
<proxies>
<!-- proxy | Specification for one proxy, to be used in connecting to the network. | -->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
1.3 That’s all !! Done !!
- Now while executing any build commands, then Maven will download required dependencies (or artifacts) from internet via this proxy
- If we got more than one <proxy> elements here, then first active (i.e.; marked true) takes the effects while executing any maven commands
Useful Eclipse IDE shortcuts :
- Eclipse IDE – How to show line numbers ?
- Eclipse IDE – How to GO TO any line number directly ?
- Eclipse IDE – How to remove unused imports ?
- Eclipse IDE – How to clean project ?
- Eclipse IDE – How to build Java project automatically ?
- Eclipse IDE – How to comment and un-comment line & block ?
- Eclipse IDE – How to generate constructor using fields ?
- Eclipse IDE – How to generate getters and setters ?
- Eclipse IDE – How to search files ?
- Eclipse IDE – How to locate methods in Java file ?
- Eclipse IDE – How to open editor using CTRL + E ?
- Eclipse IDE – Java compiler compliance level issue
Related Articles:
- Apache Maven – Introduction
- Apache Maven – Install on Windows 7 OS
- Apache Maven – Settings.xml explanation
- Apache Maven – Proxy setting explanation
- Apache Maven – pom.xml explanation
- Apache Maven – Plugins explanation
- Apache Maven – Changing default Maven repository location in Windows 7 OS
- Apache Maven – Local, Central and Remote Repositories
- Apache Maven – Installing custom library into local repository
- Apache Maven – Transitive dependencies explanation
- Apache Maven – Exclusion of Transitive dependencies
- Apache Maven – Dependency Scopes
- Apache Maven – Skipping unit test using surefire plugin
- Apache Maven – Exclusions and Inclusions of unit test
- Apache Maven – offline execution
- Apache Maven – Co-ordinates explained
- Eclipse + Maven – Integration
- Eclipse + Maven – How to import Maven project with pom.xml ?
- Eclipse + Maven – Setting M2_REPO classpath variable in IDE
- Eclipse + Maven – M2_REPO is Non Modifiable
- Eclipse + Maven – Creating and exploring projects using archetypes
- Eclipse + Maven – Converting Web project to Maven project
- Eclipse + Maven – mvn eclipse:eclipse command
- Eclipse + Maven – Plugin execution not covered by lifecycle configuration
References:
- http://maven.apache.org/guides/mini/guide-proxies.html
- http://maven.apache.org/settings.html#Proxies
- http://maven.apache.org/ref/3.2.5/maven-settings/settings.html#class_proxy
Happy Coding !!
Happy Learning !!