如何设置 JVM 使用的代理 [英] How do I set the proxy to be used by the JVM

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

问题描述

很多时候,Java 应用程序需要连接到 Internet.最常见的示例发生在读取 XML 文件并需要下载其架构时.

Many times, a Java app needs to connect to the Internet. The most common example happens when it is reading an XML file and needs to download its schema.

我在代理服务器后面.如何设置我的 JVM 以使用代理?

I am behind a proxy server. How can I set my JVM to use the proxy ?

推荐答案

来自 Java 文档(不是 javadoc API):

From the Java documentation (not the javadoc API):

http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

在命令行启动 JVM 时设置 JVM 标志 http.proxyHosthttp.proxyPort.这通常在 shell 脚本(在 Unix 中)或 bat 文件(在 Windows 中)中完成.这是 Unix shell 脚本的示例:

Set the JVM flags http.proxyHost and http.proxyPort when starting your JVM on the command line. This is usually done in a shell script (in Unix) or bat file (in Windows). Here's the example with the Unix shell script:

JAVA_FLAGS=-Dhttp.proxyHost=10.0.0.100 -Dhttp.proxyPort=8800
java ${JAVA_FLAGS} ...

在使用 JBoss 或 WebLogic 等容器时,我的解决方案是编辑供应商提供的启动脚本.

When using containers such as JBoss or WebLogic, my solution is to edit the start-up scripts supplied by the vendor.

许多开发人员都熟悉 Java API (javadocs),但很多时候会忽略文档的其余部分.它包含很多有趣的信息:http://download.oracle.com/javase/6/docs/technotes/guides/

Many developers are familiar with the Java API (javadocs), but many times the rest of the documentation is overlooked. It contains a lot of interesting information: http://download.oracle.com/javase/6/docs/technotes/guides/

更新:如果您不想使用代理来解析某些本地/内网主机,请查看@Tomalak 的评论:

Update : If you do not want to use proxy to resolve some local/intranet hosts, check out the comment from @Tomalak:

另外不要忘记 http.nonProxyHosts 属性!

Also don't forget the http.nonProxyHosts property!

-Dhttp.nonProxyHosts="localhost|127.0.0.1|10.*.*.*|*.foo.com‌​|etc"

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

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