Java 代理设置 - Ubuntu

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15710860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 20:35:59  来源:igfitidea点击:

Java proxy settings - Ubuntu

javaubuntuproxynetwork-programming

提问by nepdev

How do I set the Java proxy settings in Ubuntu (10.04 or 12.04), from the command line? What I am aiming at is to get direct connection, but by default it takes it from browser settings which are meant to go via a proxy - just I don't want Java to go via the proxy.

如何从命令行在 Ubuntu(10.04 或 12.04)中设置 Java 代理设置?我的目标是获得直接连接,但默认情况下,它从浏览器设置中获取,这些设置旨在通过代理 - 只是我不希望 Java 通过代理。

I am running an application server in Ubuntu which serves remote desktop sessions. I can put the Java control panel into the user's desktop, and then they (each individual user) can set the proxy settings under Network Settings. However - this means I have to tell each user to make this setting, which is not workable.

我在 Ubuntu 中运行一个应用程序服务器,它提供远程桌面会话。我可以将 Java 控制面板放入用户的桌面,然后他们(每个单独的用户)可以在网络设置下设置代理设置。但是 - 这意味着我必须告诉每个用户进行此设置,这是行不通的。

I want it set via some command line or environment variable on the server itself, so it defaults to "direct connection". I am not familiar with Java programming and it won't help much to give me Java code for this, I think it must be possible to set the defaults upon Java startup? Any pointers are welcome.

我希望它通过服务器本身的一些命令行或环境变量设置,所以它默认为“直接连接”。我不熟悉 Java 编程,为此提供 Java 代码也无济于事,我认为必须可以在 Java 启动时设置默认值?欢迎任何指点。

How can I do this?

我怎样才能做到这一点?

回答by Arulselvan Dhandapani

Instead of command line you can edit $javaDirectory/jre/lib/net.properties.

您可以编辑$javaDirectory/jre/lib/net.properties.

Remove #in-front of:

删除#前面的:

http.proxyHost="proxy host"
http.proxyPort="proxy port"

and set your proxy there.

并在那里设置您的代理。

回答by Suchet

You can export the http_proxyenvironment variable via command line.

您可以通过命令行导出http_proxy环境变量。

Ex:

前任:

$ export http_proxy=http://proxy-server:port

There is a environment variable ftp_proxyalso, just in case you need it.

还有一个环境变量ftp_proxy,以防万一您需要它。