Intellij Community can't use http proxy for Maven - java

I have Intellij IDEA Community installed on a Linux box that needs to use an authenticated proxy to get to the Internet. I have a system-wide proxy on the box that works, and I have the proxy configured in ~/.m2/settings.xml. Maven correctly uses the proxy when I run try it from the command-line.
I have the same proxy configured within Intellij and it gives me the plugins listing correctly. But when I try to sync with the Maven repository withing Intellij I keep getting this:
[WARNING] Unable to get resource 'org.codehaus.mojo:hibernate3-maven-plugin:pom:2.2'
from repository restlet (http://maven.restlet.org): Authorization failed: Not
authorized by proxy.
I went to Settings->Maven and put in the proxy info as properties and that didn't work. I can see by looking at those settings that Intellij is reading my ~./m2/settings.xml fine because it knows where my local repo is (it's in a non-standard place).
Anyone know how I can get this working?

Navigate to Maven > Importing1. inside the IntelliJ IDEA Settings (which is found under File > Settings).
The second last option in Maven > Importing is a field named "VM options for importer". Append the following to whatever already exists there:
-DproxySet=true -DproxyHost=myproxy.com -DproxyPort=3128
Here, replace myproxy.com with your proxy server, (e.g. http://myproxyserver.com). Replace 3128 with your proxy port (e.g. 8080).
Do the same under Maven > Runner1
Apply and close the settings window.
It should work now.
1 This may be nested under Build, Execution, Deployment > Build Tools >, depending on the version of IntelliJ you're using.

I had the same problem running maven inside IntelliJ whilst behind an NTLM proxy. The working solution was as follows:
Download and install CNTLM. Excellent post here on how to do this https://stackoverflow.com/a/23962313/3298801
Set and test your local proxy settings in IntelliJ via Settings >> System Settings >> HTTP Proxy.
In Intellij set the maven runner. Within Settings >> Maven >> runner set VM options to:
-DproxySet=true -DproxyHost=localhost -DproxyPort=3132
Restart Intellij
Note within ~/.m2/settings.xml I also added my proxy config as:
<proxies>
<proxy>
<active>true</active>
<protocol>https</protocol>
<host>localhost</host>
<port>3132</port>
</proxy>
</proxies>

A little update for memo. I don't have a standalone maven installed, so finally I fixed this by modifying the maven plugin settings. settings.xml is located at :
IntelliJ IDEA Community Edition 2017.3.4\plugins\maven\lib\maven3\conf\settings.xml
You can find proxy settings and change it as mentioned above.

I meet the same problem.By ShadowsocksR,I can visit some websites that i can't visit without ShadowsocksR. I use Intellij , the error is "Connection timed out: connect -> [Help 1]".At last, I also added my proxy config as:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<proxy>
<id>example-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>localhost</host>
<port>1080</port>
<username>***.***.**.***:****</username>
<password>*******</password>
<nonProxyHosts>www.baidu.com|*.example.com</nonProxyHosts>
</proxy>
</proxies>
</settings>
My computer environment is win10. http://maven.apache.org/guides/mini/guide-proxies.html

Can you try either removing the proxy setting in settings.xml or the setting in IntelliJ itself.
And then try to sync with the maven repo from within Intellij.

I commented out the proxy config in my ~/.m2/settings.xml file, let the Intellij Proxy info alone, and then supplied the properties in Setting->Maven. Not sure why that worked (nor why the settings.xml wasn't working right) but it's working now.

I just add it in the VM option in the run configuration, and it works
-DproxySet=true -DproxyHost=proxy.com -DproxyPort=3132
inside the IntelliJ IDEA -> edit configuration ->click on modify option -> Add VM options and add it, replace "proxy.com" with your proxy server (e.g. http://myproxyserver.com)

I Have found similar issues with the Maven 2.2 integration in intellij 9.
I am using 9.0.1
I use intellij behind a corporate firewall/proxy.
If I point Intellij's maven conf to use external Maven and maven conf that has the proxy settings inside, intellij fails to download artifacts from any remote repositories.
Had no problems with intellij-8, this only started after the upgrade. The Maven conf has not changed either.
I have to do a Maven build from command line to get any new dependent artifacts into my local repo then use intellij-9.
The Maven 2.2 integration has issues behind proxy servers.

I have had the same issue. However, my proxy settings were stored under the environment variable *M2_OPTS*.
As per the above posts, deleting the environment variables stopped IDEA from hanging.
This is under Windows 7, using IntelliJ IDEA CE 12.3
If anyone notices an open bugfix for this please respond with a link.

Related

How to let maven project work locally by intelij-idea?

We have a maven project works fine in a internet enabled environment, now we need make it work in a local environment by IntelliJ IDEA Community Edition .
we have try following actions:
in setting->build->maven:
check the box "work offline"
download all needed jars into a local folder
in settings.xml set local Repository, such as
C:\FCA\Repository
4.build the project, it seems that some packages can be find in pom.xml(no error message in pom.xml), but can't be find in java code , and build failed. You can refer to attached picture for details
How can we get it done locally? thanks a lot!
Under "Settings -> Build, Execution, Deployment -> Maven" you can find options:
Maven home directory
User settings file
Local repository
There you have to provide path to your local maven installation (by default IntelliJ has it's own Maven provided). It should automatically read your settings.xml file and set local repository. If not please also provide those two and it will work fine with your local libs.
First of all, run mvn dependency:go-offline. Then you can build in offline mode as long as you don't change any of the dependencies.
If you do this to work inside a company with several developers, think about setting up a Nexus/Artifactory for you company.

How to bypass corporate firewall/proxy for Maven

I have been trying to create a new Maven Project in Eclipse (I am using Windows 10), however when the project is created, it shows:
Errors occurred during the build.
Errors running builder 'Maven Project Builder' on project 'b'.
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6
or one of its dependencies could not be resolved: Failed to read artifact descriptor for
org.apache.maven.plugins:maven-resources-plugin:jar:2.6
When looking at the POM.xml, it shows..
I tried deleting the .m2 folder and Right-click project -> Maven -> Update Project..
It shows me..
In one solution from another SO post, it mentions the possibility of being behind a proxy.
However by checking from http://amibehindaproxy.com/ it seems I am not behind a proxy.
I tried making a Maven - Java application project in NetBeans. It seems to be working without showing any errors. But creating a new Maven project in Eclipse always shows up this error dialog box:
I also create a settings.xml in .m2 folder with the following content. Will this help me get pass the firewall/proxy restrictions?
<proxies>
<proxy>
<active>true</active>
<host>203.126.xxx.xxx</host>
<port>8080</port>
</proxy>
</proxies>
I have been trying for over 6 hours and have been browsing various similar posts in SO, I have resolved other dependency issues but unable to resolve this one.
Que: So what can I do to create a Maven project without errors from the start?
I have found the solution. I am behind the corporate firewall/proxy. It has been hard for me to get the right fix because there is no detail online guide despite numerous post asking the same question.
I am providing an (as detail as possible) guide for all future users who face the same problem.
Step 1 - Creating settings.xml
We need to setup a proxy for Maven in the settings.xml file. If this file is not auto-generated for you, use any text editor such as a notepad and paste in the following:
<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>
<proxy>
<active>true</active>
<username>your username</username>
<password>your password</password>
<host>your host</host>
<port>your port</port>
</proxy>
</proxies>
</settings>
You may also use NetBeans to create a Maven project. It will create a settings.xml for you. Then use that settings.xml file as your template.
For example:
<proxy>
<active>true</active>
<username>anderson</username>
<password>password123</password>
<host>proxy.abc.com.</host>
<port>8080</port>
</proxy>
What is my username?
I am using my own username issued to me by the company. It is also the username I use to login to my office computer (Windows username)
What my password?
I am using the password I use to login to my office computer (Windows password)
What is my host?
If you are using Windows
Internet Explorer
Connections tab
LAN Settings
Look for "Address" textbox (it should be either in "Automatic configuration" or "Proxy Server"). Either one should show you the host name (written on Address textbox). If your company is using a script file for the proxy setup like my case. Read the content of the proxy script file to determine the host name.
What is my port?
In the above step for getting the host name, you will be able to see the port number as well. If your company is using a script. Copy and paste the host on the browser. It will show up or download into your computer. Whatever file extension the script is having, you should be able to read the script content using any text editor. In the script file, you will be able to see the port number your company is using. By reading the script content, I determine my company is using port 8080.
Step 2 - Placing settings.xml in the right location
After editing/creating the settings.xml file. You can place the file in .m2 folder. The default location for me in Windows is:
C:\Users\yourUserName\.m2
If you can't determine the location, you can run the following command in command prompt:
mvn -X
Look for the location to save your settings.xml file
Step 3 - Install/Re-update dependencies / clean/build project
Right-click your problematic Maven project -> Run As -> Maven Install
Right-click your problematic Maven project -> Run As -> Maven Clean
Your problem should be resolved by now
Copy the settings.xml from (conf/settings.xml) general file
To m2/Repository.. path
Then do an update on proxy
you will find that on your IE Connection

could not read setting.xml file for maven

I had downloaded my maven plugin from eclipse market place and now i
need to set setting.xml file in window-preference-maven-user settings
block,but i am unable to find setting.xml file, i had also looked in
.m2 directory but their is only repository directory is their. so
please tell where should i look to get setting.xml. please also tell
me what is the term proxy in setting.xml file, i am new to maven so i
don't know much about this. Thanks in advance..
Download the maven installation from here. Extract the zip and there will be settings.xml.
Proxy are used so that maven use that information to download artifacts in corporate environments.
There are two locations where a settings.xml file may live:
The Maven install: ${maven.home}/conf/settings.xml
A user’s install: ${user.home}/.m2/settings.xml
See, this for detail overview.
Also , maven use maven use proxy setting to download artifacts in corporate environment. Like if you are running maven behind firewall in corporate,
Maven need to be configured with proxy settings, See here for detail.

Where is the settings.xml used by maven in the Spring Tool Suite?

I'd like to set the ftp servers for deploying from STS as described here: http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ftp.html
It should be in the settings.xml.
According to documentation settings is in either of 2:
The Maven install: $M2_HOME/conf/settings.xml
A user's install: ${user.home}/.m2/settings.xml
Where is the $M2_HOME. In other terms when working from STS(Eclipse), what is the installation folder for maven in this case. I can't find a settings.xml in ${user.home}/.m2/ .
I worked under Windows 7
Those 2 threads are related but do not provide a clear answer that worked for me at least:
maven doesnt seem to be installing with springsource tool suite
Eclipse (STS) + Maven , I have nothing appearing in the screenshot suggested in this last thread.
Thx in advance
I may be off-mark as I've never used STS myself, but if I understand correctly it is just a pre-packaged Eclipse distribution. If I'm correct your installation only contains an embedded version of Maven, but not a command line accessible one. You need to install one from here.
With the 3.x releases of Eclipse I found that you need to have your installation point to an external Maven installation for Eclipse to make use of the settings.xml files. Once you installed a downloaded version you can choose Window -> Preferences -> Maven -> Installations, press Add... and point to the version you just installed.
In Spring Tools Suite (3.6.1):
Windows - Preferences - Maven - User Settings, you can select which global- and user- version of the settings.xml to use.
Global maven settings.xml exist at apache-maven-3.0.4\conf\settings.xml [inside the maven installation]
and
Local maven settings.xml exist at C\Users\[username]\.m2\settings.xml[window OS install on C drive]

How to set NetBeans 7 internet connection?

I am using NetBeans 7. Tried to create a Maven Java project, failed.
In NetBeans
mvn.bat -DarchetypeVersion=1.1 -Darchetype.interactive=false -DgroupId=com.mycompany -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeRepository=http://repo1.maven.org/maven2/ -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes -Dbasedir=F:\\NetBeansProjects -Dpackage=com.mycompany.mavenproject1 -DartifactId=mavenproject1 "-Dmaven.repo.local=C:\\Documents and Settings\\xxx\\.m2" --batch-mode archetype:generate
It failed, because
Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central (http://repo1.maven.org/maven2): Error transferring file: Connection timed out: connect
Then copy that command into DOS, it works.
Looks like NetBeans can't connect to internet. Eclipse on the same machine can connect to remote internet.
The issue is that NetBeans 7 comes bundled with an embedded version of Maven. This means that any proxy settings you may have configured under your downloaded Maven distribution are not used by NetBeans.
You have two options:
Tools > Options > Miscellaneous > Maven > Maven Home -- point NetBeans to your existing Maven download; that is, where you have configrued settings.xml with your proxy settings;
Edit path/to/nb7/java/maven/conf/settings.xml with your proxy settings.
Well it is not necessarily internet issue
If you are behind proxies you need to tell maven in settings.xml about proxy
If that lib ins't available on the maven repos download it from official sitre and install it manually
Either
Disable antivirus firewall protection for a while.
Or
Add netbeans in exception list of the firewall.
In my case Avast firewall had blocked connection and I've disabled it for a while and it worked.
That's it !!!

Categories

Resources