How to Configure Maven to work with NTLM proxies
I recently installed Maven at a client site that had a NTLM proxy, and ran into issues because it was failing to download maven dependencies.
I was following the instructions provided by Maven to correctly setup my proxy settings, without any luck!
I kept getting the following error when attempting to run mvn install goal to set up the project:
Step #1: Add proxy settings to your Maven configuration file
- Open the Maven configuration file at %M2_HOME%/conf/settings.xml. For Linux, this is typically found at
 ${user.home}/.m2/settings.xml)
 
 For Windows, this can be found in one of the following locations:
- Find the section within settings.xmlfile that defines theproxiesnode. This should look something like:<proxies><!-- proxy| Specification for one proxy, to be used in connecting to the network.|<proxy><id>optional</id><active>true</active><protocol>http</protocol>...</proxy>--></proxies>
- Comment out the proxy node and enter your proxy information. Afterwords, the proxies node should look similar to:
 IMPORTANT: Ensure that you change the host, port, username andpassword fields to match your environment/proxy setup.<proxies><proxy><!-- id field is optional --><id>something-descriptive-to-identify-your-proxy</id><!-- Tells Maven to use this proxy. Specify'false' if you want to turn it off. --><active>true</active><protocol>http</protocol><!-- ENTER YOUR PROXY HOST NAME --><host>company.proxy.host.com</host><!-- ENTER YOUR PROXY HOST'S PORT NUMBER --><port>8080</port><!-- ENTER YOUR USER NAME TO LOGIN TO THE HOST --><username>myUserName</username><!-- ENTER YOUR PASSWORD ASSOCIATED WITH THE USERNAME --><password>myPassword</password><!-- Any URLs that you want to filter out(e.g. local repository?).Otherwise just keep this as it is --><nonProxyHosts>local.net|some.host.com</nonProxyHosts></proxy></proxies>If the above settings doesn’t work, then you might want to change the username field to include the domain that the user belongs to. e.g. 
<username>myDomain\myUserName</username>
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.jarfrom http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-http-lightweight/2.2/wagon-http-lightweight-2.2.jar
- Copy the wagon-http-lightweight-2.2.jarto%M2_HOME%/lib/extfolder.
EXAMPLE POM.XML TO TEST THE SOLUTION
To test our approach, first create a simple Maven project with the following pom.xml:
The run the Maven goal described below. This should execute successfully anddownload all Maven dependencies:
Check your local repository directory (as defined in settings.xml file) to ensure all the dependencies are correctly downloaded.
If this approache still not work for your case, then you can refer below link to set the java proxy directly for Maven.
http://www.cnblogs.com/princessd8251/p/3819327.html
备注: 这种方法配置的proxy 只对多数插件有效,笔者遇到过一个问题就是在生产 site文件的时候,
负责生产issue报表的插件org.apache.maven.plugins:maven-changes-plugin:2.9 不主动去读这个配置,后面还是在MVN.bat里面配置的代理解决问题。
但是有些插件比如org.apache.maven.plugins:maven-site-plugin:3.3 在执行site:deploy的时候,只会查找settings.xml里面的proxy设置,会忽略掉MVN.bat里的设置.
所以最好的办法还是MVN.BAT和settings.xml里面都设置.
settings.xml 配置
    <proxies>
        <proxy>
            <active>true</active>
            <protocol>https</protocol>
            <host>xxxxx</host>
            <port>8080</port>
            <username>dummy\dummy</username>
            <password>dummy</password>
        </proxy>
    </proxies>
mvn.bat 配置
"-Dhttps.proxyHost=xxxxx" "-Dhttps.proxyPort=8080" "-Dhttps.proxyUser=dummy\dummy" "-Dhttps.proxyPassword=dummy"
 
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号