views:

26

answers:

2

I'm using Ubuntu with Gnome where I can set network proxy settings (with authentication).

The question is: how I can run maven in command line and make it use this proxy?

A: 

Did you take a look at http://maven.apache.org/guides/mini/guide-proxies.html?

In your settings.xml:

<settings>
  .
  .
  <proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
    </proxy>
  </proxies>
  .
  .
</settings>
The Alchemist
+1  A: 

There is a java.net.useSystemProxies system property that can be set to true (on Windows and Linux platforms) to tell the JVM to use the system proxy settings. From the Java Networking and Proxies guide:

Before we see in details how to write such a ProxySelector, let's talk about the default one. J2SE 5.0 provides a default implementation which enforces backward compatibility. In other terms, the default ProxySelector will check the system properties described earlier to determine which proxy to use. However, there is a new, optional feature: On recent Windows systems and on Gnome 2.x platforms it is possible to tell the default ProxySelector to use the system proxy settings (both recent versions of Windows and Gnome 2.x let you set proxies globally through their user interface). If the system property java.net.useSystemProxies is set to true (by default it is set to false for compatibility sake), then the default ProxySelector will try to use these settings. You can set that system property on the command line, or you can edit the JRE installation file lib/net.properties, that way you have to change it only once on a given system.

But this will only work for the java.net.* classes, not for commons-httpclient, jsch, etc. So this doesn't solve the whole issue and Maven doesn't really support it (this is logged as MNG-728).

In other words, I'm afraid you'll have to configure the proxy settings in your ~/.m2/settings.xml.

Pascal Thivent