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

查看:1087
本文介绍了如何设置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 do I set my JVM to use the proxy ?

推荐答案

从Java文档( not 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.proxyHost http.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天全站免登陆