Does Java have a default System Environment Variable that will always be read/appended when we set it? CATALINA_OTPS
/JAVA_OPTS
etc seems only for TOMCAT/JBOSS etc.
Update: Added item # 4 and 5. Remove OS from title to make my question clearer.
Update 2: After looking at Perception's answer, it seems like my item 2 and 3 can be achieved via System.getenv
. How to achieve item 4 and 5?
Here is example of scenario:
Imagine now JAVA_DEFAULT_OPTS
is an environment variable that will be read by Java as it has now become the standard. On development desktop machine, I set JAVA_DEFAULT_OPTS=-DLOG_LEVEL=DEBUG -Xmx384m
; On production server machine, customers set JAVA_DEFAULT_OPTS=-DLOG_LEVEL=INFO -Xmx1024m
. When I/users double click the jar file on Windows, the application will run will different log4j level and max memory heap size.
General Information. The PATH is the system variable that your operating system uses to locate needed executables from the command line or Terminal window. The PATH system variable can be set using System Utility in control panel on Windows, or in your shell's startup file on Linux and Solaris.
You can also type where java at the command prompt. Click the Environment Variables button. Under System Variables, click New. In the Variable Value field, enter your JDK or JRE installation path .
There is a special environment variable called _JAVA_OPTIONS
, its value will be picked up by the JVM (java.exe).
In Windows:
set _JAVA_OPTIONS=-Xms64m -Xmx128m -Dawt.useSystemAAFontSettings=lcd
In Linux:
export _JAVA_OPTIONS='-Xms64m -Xmx128m -Dawt.useSystemAAFontSettings=lcd'
For Java Web Start it's JAVAWS_VM_ARGS
. For javaw.exe (Applet), it's _JPI_VM_OPTIONS
.
edit 20201213
_JAVA_OPTIONS
environment variable was ok but was not documented or supported.
Since it is not standardized, other vendors have their own names e.g. IBM_JAVA_OPTIONS
. Leading underscore names are private by convention so it's not a good idea to standardize the usage of _JAVA_OPTIONS
.
That's why JAVA_TOOL_OPTIONS
should be the preferred choice.
ref : https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#tooloptions
Java has a standard OS system environment variable that is always set when the JVM is launched:
All accessible via 'System.getProperty(propertyName)`
If you need anything more than this you could always use the Management API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With