Skip to content

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

enter image description here

I tried deleting the .m2 folder and Right-click project -> Maven -> Update Project..

It shows me..

enter image description here

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.

enter image description here

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:

enter image description here

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?

Answer

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?

enter image description here

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:UsersyourUserName.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

enter image description here

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