Close Menu
Java HelpsJava Helps
    What's Hot

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022
    Facebook X (Twitter) Instagram
    Java HelpsJava Helps
    • Home
    • How To
      1. Install
      2. Run
      3. Configure
      4. View All

      How to Install MySQL with phpMyAdmin on Ubuntu?

      December 4, 2022

      Install The Latest IntelliJ IDEA on Linux

      November 28, 2022

      Install The Latest Apache Maven on Linux

      November 27, 2022

      Install The Latest Oracle JDK on Linux

      November 27, 2022

      Run NiFi Cluster in Docker with SSL Enabled

      December 6, 2022

      How to Run Apache NiFi Docker on Mac M1?

      December 1, 2022

      How to Run Apache NiFi on Docker?

      December 1, 2022

      Create A New Maven Project In IntelliJ IDEA

      November 29, 2022

      Things To Do After Installing IntelliJ IDEA

      December 20, 2022

      How to Set Proxy for IntelliJ IDEA?

      December 20, 2022

      How to Set Proxy for Maven?

      December 6, 2022

      How to Create a Fat JAR Using Maven?

      December 5, 2022

      Things To Do After Installing IntelliJ IDEA

      December 20, 2022

      How to Set Proxy for IntelliJ IDEA?

      December 20, 2022

      Manage GitHub Artifact Storage Quota

      December 6, 2022

      Run NiFi Cluster in Docker with SSL Enabled

      December 6, 2022
    • Hello World
      1. Framework
      2. Library
      3. View All

      JPA Hello World! using Hibernate and MySQL

      December 3, 2022

      Jersey 3.x – Hello World!

      December 2, 2022

      Microservices Framework for Java (MSF4J) – Hello World!

      December 1, 2022

      How to Parse PCAP files in Java?

      November 30, 2022

      JPA Hello World! using Hibernate and MySQL

      December 3, 2022

      Jersey 3.x – Hello World!

      December 2, 2022

      Microservices Framework for Java (MSF4J) – Hello World!

      December 1, 2022

      How to Parse PCAP files in Java?

      November 30, 2022
    • More
      • Privacy Policy
        • Java Helps
        • Android Apps
      • Contact US
      • About
    Facebook X (Twitter) Instagram
    Java HelpsJava Helps
    Home » How to Set Proxy for Maven?
    Apache Maven
    Apache Maven
    Configure

    How to Set Proxy for Maven?

    Gobinath LoganathanBy Gobinath LoganathanDecember 6, 2022Updated:December 6, 2022No Comments3 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest Email

    If your computer connects to the Internet through a proxy server, Apache Maven has to be configured with the proxy settings to connect to the public Maven repository. Without the proxy setting, most likely Apache Maven will throw timeout errors when attempting to resolve dependencies. This issue can also propagate into your IDEs such as Eclipse or IntelliJ IDEA. This article explains how to set proxy for Maven and update those changes in both IntelliJ IDEA and Eclipse.

    Set Proxy in settings.xml

    Step 1:
    Open the settings.xml file from the following location. If you do not have this file already, skip this step and go to Step 2.

    Operating SystemLocation
    Linux~/.m2/settings.xml
    Mac~/.m2/settings.xml
    WindowsC:\Users\{Username}\.m2\settings.xml

    Step 2:
    Add the following configuration inside the settings tag. If you are creating this file for the first time, copy and paste the final output into a new editor.

    <proxies>
    <!-- Proxy for HTTP -->
    <proxy>
    <id>optional</id>
    <active>true</active>
    <protocol>http</protocol>
    <username>proxyuser</username>
    <password>proxypass</password>
    <host>proxy.host.net</host>
    <port>80</port>
    <nonProxyHosts>local.net</nonProxyHosts>
    </proxy>

    <!-- Proxy for HTTPS -->
    <proxy>
    <id>optional</id>
    <active>true</active>
    <protocol>https</protocol>
    <username>proxyuser</username>
    <password>proxypass</password>
    <host>proxy.host.net</host>
    <port>80</port>
    <nonProxyHosts>local.net</nonProxyHosts>
    </proxy>
    </proxies>

    After adding the proxy configuration, the full settings.xml should look like this:

    <?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">
    <pluginGroups/>
    <proxies>
    <!-- Proxy for HTTP -->
    <proxy>
    <id>optional</id>
    <active>true</active>
    <protocol>http</protocol>
    <username>proxyuser</username>
    <password>proxypass</password>
    <host>proxy.host.net</host>
    <port>80</port>
    <nonProxyHosts>local.net</nonProxyHosts>
    </proxy>

    <!-- Proxy for HTTPS -->
    <proxy>
    <id>optional</id>
    <active>true</active>
    <protocol>https</protocol>
    <username>proxyuser</username>
    <password>proxypass</password>
    <host>proxy.host.net</host>
    <port>80</port>
    <nonProxyHosts>local.net</nonProxyHosts>
    </proxy>
    </proxies>

    <servers/>
    <mirrors/>
    <profiles/>
    </settings>

    Step 3:
    Modify the configurations according to your network proxy settings. Leave the username and password empty, if they are not applicable for you. For example, if the proxy host is cache.javahelps.com and the port number is 3128, your proxy settings should look like this:

    <?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">
    <pluginGroups/>
    <proxies>
    <!-- Proxy for HTTP -->
    <proxy>
    <id>optional</id>
    <active>true</active>
    <protocol>http</protocol>
    <username></username>
    <password></password>
    <host>cache.javahelps.com</host>
    <port>3128</port>
    <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>

    <!-- Proxy for HTTPS -->
    <proxy>
    <id>optional</id>
    <active>true</active>
    <protocol>https</protocol>
    <username></username>
    <password></password>
    <host>cache.javahelps.com</host>
    <port>3128</port>
    <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    </proxies>

    <servers/>
    <mirrors/>
    <profiles/>
    </settings>

    Step 4:
    After making all the changes, save the file to the following location.

    Operating SystemLocation
    Linux~/.m2/settings.xml
    Mac~/.m2/settings.xml
    WindowsC:\Users\{Username}\.m2\settings.xml

    Update the Changes in Apache Maven CLI

    You don’t need to make any further changes for the Apache Maven CLI to use the proxy. However, if you already tried the Maven command before making the changes and it failed due to the proxy error, Apache Maven may not retry downloading the files. To force Maven to redownload, run the following command from the project parent folder. It will remove the dependencies from the local Maven repository and redownload them again.

    mvn dependency:purge-local-repository

    After running the above command, if you run your usual build command, the build should succeed given there are no other errors and you configured the proxy correctly.


    Update the Changes in IntelliJ IDEA

    Step 1:
    IntelliJ IDEA also uses Apache Maven behind the scene to build the project if it is a Maven project. Therefore, run the following command from the IntelliJ terminal or system terminal to redownload the dependencies.

    mvn dependency:purge-local-repository

    Step 2:
    Reload the Maven project by right-clicking on the project and selecting the Maven → Reload Project menu.

    Reload Apache Maven Project in IntelliJ IDEA

    Step 3 (only if Step 2 doesn’t work):
    In the worst case if it doesn’t help, go to the IntelliJ IDEA settings → Build, Execution, Deployment → Build Tools → Maven and make sure the User settings file is pointing to the settings.xml file you modified in the first part of this article. Apply the changes by clicking on “Apply” and “OK”.

    IntelliJ IDEA Maven Settings


    Update the Changes in Eclipse

    Step 1:
    Similar to IntelliJ IDEA, Eclipse also uses Apache Maven to build maven projects. Therefore, run the following command from the terminal to redownload the dependencies.

    mvn dependency:purge-local-repository

    Step 2:
    Go to Window → Preferences → Maven → User Settings. Make sure the User settings file is pointing to the settings.xml file you modified in the first part of this article and click the “Update Settings” button. Apply the changes by clicking the “Apply and Close” button.

    Eclipse Maven Settings

    Step 3:
    Reload the Maven project by right-clicking on the project and selecting the Maven → Update Project menu.

    Reload Maven project in Eclipse

    Have you found this article useful? Please let me know below in the comments. Knowing someone found my articles useful motivates me to write more. Also, comment below if you face any issues with following this article or getting it working. I will try my best to help you resolve the problem. The Java Helps community is also willing to help each other and grow together.

    eclipse intellij maven
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    How to Create a Fat JAR Using Maven?

    December 5, 2022

    Create Scala Project with Maven in IntelliJ IDEA

    December 4, 2022

    How to Add MySQL JDBC Driver to Eclipse?

    December 4, 2022

    How to Disable Hibernate Logs in the Output?

    December 3, 2022
    Don't Miss
    Configure

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    IntelliJ Idea: the famous IDE for JVM languages including Java, Scala, and Kotlin. If you…

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022

    Manage GitHub Artifact Storage Quota

    December 6, 2022
    Our Picks

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022

    Manage GitHub Artifact Storage Quota

    December 6, 2022
    About Us
    About Us

    Java Helps is the platform to share all about the Java ecosystem. All the sample code available on Java Helps articles are published under Apache 2.0 License. Readers are free to use them according to the Apache 2.0 License.

    "The world is my town; its people my kinsmen."
    -Kaṉiyan Pūngunṟanār

    Email Us: www.javahelps@gmail.com

    Our Picks

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022
    New Comments

      Type above and press Enter to search. Press Esc to cancel.

      Go to mobile version