56

Can anyone explain what does Java do when _JAVA_OPTIONS Environment variable defined & when application launched on the windows machine?

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
Madan
  • 691
  • 1
  • 5
  • 9
  • 1
    See also [Difference between _JAVA_OPTIONS JAVA_TOOL_OPTIONS and JAVA_OPTS](http://stackoverflow.com/questions/28327620/difference-between-java-options-java-tool-options-and-java-opts) – Vadzim Oct 27 '15 at 20:29
  • I don't know but I found _JAVA_OPTIONS in my registry under HKCU/Environment. I delete that environment key and it really helped (Gradle was choking since I had an option in there pointing to a folder that I no longer had access to) – johnjps111 Aug 19 '21 at 16:11

2 Answers2

60

You can use _JAVA_OPTIONS to pass options to any JVM process started on your system.

For example,

set _JAVA_OPTIONS=-Dsun.java2d.noddraw=true

When a JVM starts, it parses the value of _JAVA_OPTIONS as if the parameters were at the command line of java. You can see the passed parameters via JVisualVM.

For more information, read the blog post: What I discovered while trying to pass Default JVM Parameters

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
Demi Ben-Ari
  • 821
  • 6
  • 6
  • 9
    It is generally considered good practice to copy the relevant section into the answer, as blogs and other external references end up getting deleted. – Joeblade Dec 30 '14 at 10:32
  • Thanks for the comment, Will do in the future, but the answer was just too long to write in the comment. – Demi Ben-Ari Jan 28 '15 at 06:28
  • 4
    It is better to use JAVA_TOOL_OPTIONS instead of _JAVA_OPTIONS as per https://bugs.openjdk.java.net/browse/JDK-4971166 – Kamaraju Kusumanchi May 05 '17 at 23:09
29

And according to https://bugs.openjdk.java.net/browse/JDK-4971166 undocumented Hotspot-specific _JAVA_OPTIONS was superseded by JAVA_TOOL_OPTIONS that is included in standard JVMTI specification, does better handling of quoted spaces and should be always preferred.


Since JDK 9+ there's also JDK_JAVA_OPTIONS as the preferred replacement, see What is the difference between JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS when using Java 11?

Vadzim
  • 24,954
  • 11
  • 143
  • 151