简体   繁体   中英

How can i set a global variable for Java so that it puts all java applets through a proxy?

I am trying to figure out how to make it so all java applications running on the machine are put through a provided proxy. I am doing this because the application that will be running does not support proxies by default and due to the circumstance i can not just give it command arguments. Below is what I have found so far and I have triied both the _JAVA_OPTIONS, JAVA_TOOL_OPTIONS, and _JPI_VM_OPTIONS. The application I am trying to work with is minecraft.

Prior to this issue I couldnt determine why my proxy application that I have built in C# using Titanium Web Proxy was not picking up on the minecraft traffic, and I have come to the conclusion that it is because it is not using the system's proxy. Here are the commands I have used to try setting the variable that are still not causing the JVM to go through the proxy.

  • set _JAVA_OPTIONS=-Djava.net.useSystemProxies=true
  • set _JPI_VM_OPTIONS=-Djava.net.useSystemProxies=true
  • set JAVA_TOOL_OPTIONS=-Djava.net.useSystemProxies=true

Guess my question is, is this possible?

If you find yourself using the same options over and over before laucing a java process, you can set up a special environment variable to contain your default options and the JVM will pick up the the values. If the Java process is launch via java.exe then the environment variable is called _JAVA_OPTIONS (see JAVA_TOOL_OPTIONS below for a better option),

eg In Windows:

set _JAVA_OPTIONS=-Xms64m -Xmx128m -Dawt.useSystemAAFontSettings=lcd In Linux: export _JAVA_OPTIONS='-Xms64m -Xmx128m -Dawt.useSystemAAFontSettings=lcd' ref: https://docs.oracle.com/javase/8/docs/technotes/guides/2d/flags.html If the Java process is launch via javaw.exe (Applet) then the environment variable is called _JPI_VM_OPTIONS.

For example:

_JPI_VM_OPTIONS = -Dsome.property=true For a Java Web Start process (javaws.exe), the environment variable is called JAVAWS_VM_ARGS.

For example:

JAVAWS_VM_ARGS = -Dsome.property=true But.. The preferred way is to use an environment called JAVA_TOOL_OPTIONS. _JAVA_OPTIONS environment variable was ok but was not documented or supported. Since it is not >standardized, other vendors have their own names eg IBM_JAVA_OPTIONS. Leading underscore names are >private by convention so it's not a good to standardize the usage of _JAVA_OPTIONS. That's why >JAVA_TOOL_OPTIONS should be the preferred choice.

Maybe this question on the Arqade (another StackExchange site) can help: How can I play Minecraft through a proxy server? ; or, among others on StackOverflow, How do I set the proxy to be used by the JVM

Basically setting JAVA_TOOL_OPTIONS to include -Dhttp.proxyHost=proxyURL -Dhttp.proxyPort=proxyPORT -Dhttps.proxyHost=proxyURL -Dhttps.proxyPort=proxyPORT

( java.net.useSystemProxies should also work... but maybe minecraft (starter) is not respecting these settings - I believe you can set options in the starter as well)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM