How config Maven to work with NTLM proxy
I have been worked with Maven [+] some time and I can to affirm that is one the best tools to the management of software projects and comprehension, incredibly powerfull, versatile, but far from unanimous among developers. I like to show that is a personal opinion and I respect all other points of view.
This post was born from the necessity of install Maven on my developer environment, that has a kind of proxy (NTLM), because until then I saw situations where only was necessary configure the settings.xml file, like described on Maven documentation (Maven configurando proxy).
(*)%M2_HOME% = > It's an Environment global variable to the binary path of Maven
This post was born from the necessity of install Maven on my developer environment, that has a kind of proxy (NTLM), because until then I saw situations where only was necessary configure the settings.xml file, like described on Maven documentation (Maven configurando proxy).
Error Message
The error message below was constantly displayed when I tried to run the mvn clean install command in the project:
C:Dev\MavenTest> mvn clean install[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifaescriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1: Could not transfer artifact org.apache.maven.plugins:maven-clean-plISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. ). -> [Help 1]:pom:2.4.1 from/to central (http://repo.maven.apache.org/maven2): Not authorized by proxy, ReasonPhrase:Proxy Authentication Required (...
Step by step to resolve the problem
Step #1: Add the proxy data configurations on the maven configuration file
1. Open Maven configuration file on: %M2_HOME%/conf/settings.xml(*)(*)%M2_HOME% = > It's an Environment global variable to the binary path of Maven
#Default Windows 7/8
C:\users\username\.m2\settings.xml
2. Find on file settings.xml the session where can be defined the proxy configurations. Such as example below:
<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>
3. Uncomment the tags and add yours proxy configurations, example below:
<proxies><proxy> <!-- id --> <id>Something to describe and identify your proxy server</id>
<!-- Change the value to 'true' and the Maven will use the proxy to access the internet. The 'false' if you wish turn off the access by proxy. --> <active>true</active> <protocol>http</protocol> <!-- Add the proxy hostname --> <host>company.proxy.host.com</host> <!-- Add the proxy port --> <port>8080</port> <!-- Add the proxy login --> <username>myUserName</username> <!-- Add the proxy password --> <password>myPassword</password> <!-- Add the proxy exclusions --> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> </proxies>
Attention: Validate all data used host, port, username and password to avoid problens on proxy access.
Tip
Some kinds of proxy need extra data, sometimes can occur errors even with all data correct. If this occur with you try to put the domain before the username, such as example below:
<username>myDomain\myUserName</username>
Some kinds of proxy need extra data, sometimes can occur errors even with all data correct. If this occur with you try to put the domain before the username, such as example below:
<username>myDomain\myUserName</username>
Step #2: Add the lib wagon-http-lightweight in the extension folder
The lib Wagon HTTP lightweight allows Maven through the limitation of working with NTLM proxies. Follow the steps below to add the lib Wagon HTTP lightweight like a Maven extension:
1. Download the library wagon-http-lightweight-2.2.jar at: http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-http-lightweight/2.2/wagon-http-lightweight-2.2.jar
2. Copy the wagon-http-lightweight-2.2.jar to the %M2_HOME%/lib/ext folder.
3. Run the Maven command with the desired object, such as below. This should run successfully and all dependencies will be successfully downloaded.
mvn Clean install
Verify your local repository (such as defined on settings.xml file) to be sure that all dependencies are being downloaded correctly.
Comentários
Postar um comentário