Maven proxy settings – Eclipse, command line and global settings

Learn to configure maven https proxy settings. By default, maven uses default network connection while running on the local systems. But sometimes we are running our application in our workplace or company. These networks shields the internet usage through proxy servers or firewalls, so all internet queries made from our system goes through this proxy server.

Maven by default does not detect network proxy configuration, and to use maven in these restricted areas, we must configure network proxy settings for maven.

Read More: Maven installation

1. How to configure maven proxy settings

To setup maven proxy setting, follow below steps:

  • Navigate to path – {M2_HOME}/conf/settings.xml
  • Open file settings.xml in edit mode in any text editor.
  • Open and update <proxy> tag.

This tag will look like this:

<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">

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

</settings>

Update above proxy server fields with your network specific credentials. You can found network proxy details in your browser’s connection settings. For example, proxy settings can be found at –

Internet Explorer >> tools >> internet options >> Connections >> LAN Settings

Firefox >> tools >> options >> ADVANCED TAB >> settings

2. Maven proxy settings example

Given is sample network proxy setting entries.

<!-- 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>https</protocol>
		<username>lokesh</</username>
		<password>abc123</password>
		<host>webproxy.company.com</host>
		<port>8081</port>
		<!-- <nonProxyHosts>local.net|some.host.com</nonProxyHosts> -->
	</proxy>
	-->
</proxies>

After following above steps, you should be able to use maven behind proxy servers also.

3. Maven proxy settings in Eclipse

To use proxy settings in eclipse while using maven, follow these steps:

  • Open your Eclipse and go to Window -> Preferences.
  • Click on the Browse button of User Settings, and select the settings.xml.

    Maven proxy in eclipse
    Maven proxy in eclipse
  • Click on the "Update Settings" button to update the settings. If any confirmation dialog appeared, just click Yes.

4. Maven proxy settings from command line

To save time, we can append proxy details at the end of maven commands.

$ mvn clean install -DproxySet=true -DproxyHost=ur.proxy.server -DproxyPort=port

Though it’s possible to set maven proxy from command line, still it is recommended to use global proxy settings in settings.xml file.

Happy Learning !!

Reference:

Configuring a proxy

Was this post helpful?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

6 thoughts on “Maven proxy settings – Eclipse, command line and global settings”

  1. Hi Lokesh,
    how configure Proxy Settings in Maven in the case when I use “Use system Settings” for Proxy Settings ( i.e. I do not have specified Proxy in Tools->Options-> Advanced TAB -> Network..)?
    What I must to do to take System Settings for Proxy?
    I ask this because I have problem with downloading some plugins.
    I am getting this error after entering mvn archetype:generate -DgroupId=com.howtodoinjava -DartifactId=demoWebApplication
    -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false in cmd

    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven- clean-plugin/2.5/maven-clean-plugin-2.5.pom
    clean-plugin/2.5/maven-clean-plugin-2.5.pom
    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-clean-plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or on
    e of its dependencies could not be resolved: Failed to read artifact descriptor
    for org.apache.maven.plugins:maven-clean-plugin:jar:2.5
    

    If I try to see this plugin manually in web browser there is no Problem. Another Problem I had is in no recognization of some certifikates, and I can not download in process of creation maven Project some Things. I think this is slao connected wit Proxy Settings, because when I Bypass Proxy I do not have Problem with no recognition of cerfifikates. But at the end I must use Proxy. So my last question is how set properly maven Project to avoid above described Problems.

    Thanks.

    Reply
  2. optional
    true
    http
    proxyuser
    proxypass
    proxy.host.net
    80
    local.net|some.host.com

    This setting is mandatory in settings.xml.

    I dont want to take this proxy details form settings.xml.

    Maven or eclipse should take directly system proxy settings.

    Is it possible?

    Please confirm.

    Reply

Leave a Comment

HowToDoInJava

A blog about Java and related technologies, the best practices, algorithms, and interview questions.