如何使Maven使用系统代理设置 [英] How to make maven use system proxy settings

查看:568
本文介绍了如何使Maven使用系统代理设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Ubuntu与Gnome结合使用,可以在其中设置网络代理设置(通过身份验证).

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

问题是:如何在命令行中运行maven并使其使用此代理?

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

推荐答案

有一个java.net.useSystemProxies系统属性,可以将其设置为true(在Windows和Linux平台上),以告知JVM使用系统代理设置. .从 Java网络和代理指南:

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:

在详细了解如何编写这样的ProxySelector之前,让我们谈谈默认值. J2SE 5.0提供了一个默认实施,该实施强制了向后兼容性.换句话说,默认的ProxySelector将检查前面所述的系统属性,以确定要使用哪个代理.但是,有一个新的可选功能:在最新的Windows系统和Gnome 2.x平台上,可以告诉默认的ProxySelector使用系统代理设置(Windows和Gnome 2.x的最新版本都可以让您使用通过其用户界面全局设置代理).如果系统属性java.net.useSystemProxies设置为true(出于兼容性考虑,默认情况下将其设置为false),则默认的ProxySelector将尝试使用这些设置.您可以在命令行上设置该系统属性,也可以编辑JRE安装文件lib/net.properties,这样一来,您只需在给定的系统上对其进行一次更改即可.

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.

但这仅适用于java.net.*类,不适用于commons-httpclient,jsch等.因此,这不能解决整个问题,并且Maven并不真正支持它(此记录为 MNG-728 ).

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

换句话说,恐怕您必须在~/.m2/settings.xml中配置代理设置.

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

这篇关于如何使Maven使用系统代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆