9

My eclipse installation always uses the https protocol to download repository structures. The problem is that my cooperate proxy wont let me use https on this url. How to force m2e to use http?

I tried with different external maven installations for m2e but no luck. It only works if i use the external maven from CLI, which uses http.

calaedo
  • 313
  • 1
  • 3
  • 15

2 Answers2

15

I'd recommend using an external Maven installation anyway, don't rely on the built-in version. In your Maven directory, find the <maven>/conf/settings.xml file. There you can edit your proxy settings:

<settings>
  <proxies>
   <proxy>
      <id>example-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.example.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
    </proxy>
  </proxies>

  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>insecurecentral</activeProfile>
  </activeProfiles>
  <profiles>
    <profile>
      <id>insecurecentral</id>
      <!--Override the repository (and pluginRepository) "central" from the Maven Super POM -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://repo1.maven.org/maven2</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://repo1.maven.org/maven2</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
</settings>

Also, you should update your Maven settings in Eclipse (Maven -> User Settings):

Maven User Settings

user1438038
  • 5,821
  • 6
  • 60
  • 94
  • The problem is that m2e uses https for the central repository in their Super-POM and i have to use http because https is blocked – calaedo Aug 17 '15 at 12:30
  • 2
    You can also use http://repo1.maven.org/maven2 in your settings to access Maven Central using http instead. I've edited my answer above. – user1438038 Aug 17 '15 at 12:34
  • 2
    Why edit /conf/settings.xml instead of creating a new configuration file in your home folder (~/.m2/settings.xml) and make the settings suggested above there? – rec Aug 17 '15 at 14:52
  • 1
    Either way should work. When facing problems with Maven, people often suggest deleting the ``.m2`` directory, so I would rather put my configuration in ``/conf/settings.xml``. If both, a global configuration and a user configuration exist, [they will be merged](http://maven.apache.org/settings.html#Quick_Overview), with the user-specific ``settings.xml`` being dominant. – user1438038 Aug 18 '15 at 07:02
  • "*I'd recommend using an external Maven installation*" Can you elaborate? How would we use an external Maven with Eclipse? – Stevoisiak Oct 06 '17 at 14:52
  • 1
    @StevenVascellaro: Sure. Install standalone Maven, set up environment variables and then point your Eclipse configuration to that external Maven installation (i.e. _Window > Properties > Maven > Installations_). – user1438038 Oct 10 '17 at 14:02
  • @user1438038, Seems maven change the default repo id from `central` to `central-repo`, please refer to Machado's answer. – hao Nov 14 '17 at 10:51
  • @hao: There is no such thing as a default repository id. You simply have to pick a **unique id** to refer to a Maven repository. If you encounter any problems, check if there is any other repository with the same id in your ``pom.xml`` file. – user1438038 Nov 14 '17 at 13:54
8

I had a similar problem and I fixed that adding the code below to my pom.xml:

<repositories>
    <repository>
        <id>central-repo</id>
        <name>Central Repository</name>
        <url>http://repo1.maven.org/maven2</url>
    </repository>
</repositories>
Marcel
  • 2,810
  • 2
  • 26
  • 46