17

I am trying to access maven repository from behind proxy. I configured settings.xml correctly (i guess so...)

  <proxies>
    <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <username>username</username>
      <password>password</password>  
      <host>12.34.56.78</host>
      <port>8080</port>
    </proxy>
  </proxies>

But still I am getting an error message like... if i don't configure userid/password gets correct error message which is HTTP response code 407 - saying authentication required. But If I configure correct/incorrect proxy authentication it always prints below error message....

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.pom
[WARNING] Unable to get resource 'org.apache.maven.plugins:maven-clean-plugin:pom:2.2' from repository central (http://repo1.maven.org/maven2): Error trans
ferring file: Server redirected too many  times (20)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.pom
[WARNING] Unable to get resource 'org.apache.maven.plugins:maven-clean-plugin:pom:2.2' from repository central (http://repo1.maven.org/maven2): Error trans
ferring file: Server redirected too many  times (20)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • Can you give a snippet of your settings.xml file how you configured the proxy, cause this sounds like not correct port/username/password etc. – khmarbaise May 18 '10 at 08:05
  • true http AP\daunddig P00nam-5 10.83.2.8 8080 –  May 18 '10 at 08:51

4 Answers4

38

If above does not work

Step #2: Add wagon-http-lightweight extension

Wagon HTTP lightweight library allows us to overcome authentication limitations in Maven (3.0.4) when working with NTLM proxies. We can follow the steps below to add the Wagon HTTP lightweight library as a Maven extension:

  • Download the wagon-http-lightweight-2.2.jar from here.

  • Copy the wagon-http-lightweight-2.2.jar to %M2_HOME%/lib/ext folder.

Example pom.xml to test the solution

To test our approach, first create a simple Maven project with the following pom.xml:

<!-- pom.xml -->
<project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.thira.testmavenplugindl</groupId>
  <artifactId>test-maven-plugin-dl</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>Test Maven Plugin Download Issue</name>
  <description>Example pom file to test Maven dependency download with NTLM proxies</description>
</project>

The run the Maven goal described below. This should execute successfully and download all Maven dependencies:

mvn clean install

Check your local repository directory (as defined in settings.xml file) to ensure all the dependencies are correctly downloaded.

Stanislav Mamontov
  • 1,734
  • 15
  • 21
Mohammed Rafeeq
  • 2,586
  • 25
  • 26
  • 2
    Thank you, this is single solution which helped me to deal with NTLM! – Stanislav Mamontov Dec 27 '13 at 07:52
  • 1
    though this posting is more than 3 years old, it save my day! thx. – Funkwecker Feb 07 '17 at 14:38
  • https://stackoverflow.com/questions/10033286/maven-proxy-settings-not-working/10625020#10625020 -- I think this basically describes the same solution, but without the need to manually download and copy files – qqilihq Jul 16 '17 at 18:29
7

Another alternative is to get Cntlm (http://cntlm.sourceforge.net/) on your machine, configure your NTLM proxy in cntlm.ini with your domain/password/proxy name etc. run it :

cntlm.exe -v -a NTLMv2 -c cntlm.ini

Edit your maven $MAVEN_HOME\conf\settings.xml, and use proxies block:

<proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>localhost</host>
      <port>3128</port>
      <nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
   </proxy>
</proxies>

Now run maven with -s option:

mvn -s $MAVEN_HOME\conf\settings.xml <goal>
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • 1
    It seems like the m2eclipse ignores the proxy configuration of the user's settings.xml as adding the same proxy configuration to the global settings.xml resolves the issue. – Christoffer Soop Mar 03 '15 at 09:44
7

Is it a NTLM proxy? If yes, try to supply domainname\username for the username (as suggested in this thread).

<username>DOMAINNAME\USERNAME</username>
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • Yes I tried username with domain name and withouth domain name. but still it fails. –  May 18 '10 at 08:50
  • 1
    @DigambarDaund: can you run maven with -X to see if you get useful information? – Pascal Thivent May 18 '10 at 09:05
  • 1
    @KhueVu it is obvious! you are changing proxy settings into the settings.xml file which you downloaded from site and you are running m2e which uses bundled maven so you have to go to preferences and change maven prefereces-> installations to point to your local maven installation which contains edited settings.xml by default Embedded is the value just change it! – positivecrux Feb 09 '16 at 14:18
0

I too stumble upon this issue, spent a lot of time to search for a solution to NTLM error. NTLM issue does not get away even if we prefix user name with domain name just in proxy tag, we also need to prefix user ids in server tags like given below...

<server>
    <id>isb-libs-dev</id>
    <username><internal.java.corp>\username</username>
    <password>password</password>
</server>
Yogesh Manware
  • 1,843
  • 1
  • 22
  • 25