How do I set the proxy to be used by the JVM

2018-12-31 09:03发布

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.

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

标签: java proxy jvm
20条回答
皆成旧梦
2楼-- · 2018-12-31 09:33

Set the java.net.useSystemProxies property to true. You can set it, for example, through the JAVA_TOOL_OPTIONS environmental variable. In Ubuntu, you can, for example, add the following line to .bashrc:

export JAVA_TOOL_OPTIONS+=" -Djava.net.useSystemProxies=true"

查看更多
还给你的自由
3楼-- · 2018-12-31 09:33

You can utilize the http.proxy* JVM variables if you're within a standalone JVM but you SHOULD NOT modify their startup scripts and/or do this within your application server (except maybe jboss or tomcat). Instead you should utilize the JAVA Proxy API (not System.setProperty) or utilize the vendor's own configuration options. Both WebSphere and WebLogic have very defined ways of setting up the proxies that are far more powerful than the J2SE one. Additionally, for WebSphere and WebLogic you will likely break your application server in little ways by overriding the startup scripts (particularly the server's interop processes as you might be telling them to use your proxy as well...).

查看更多
登录 后发表回答