Java System Environment Variable

Does Java have a System Environment Variable that will always be read / added when we set it? CATALINA_OTPS / JAVA_OPTS etc. seems to be only for TOMCAT / JBOSS etc.

  • I don't want to install it through the properties of the Java system (which is passed through -Dprop1 = value1 -Dprop2 = value2), since it includes a shell / script package.
  • It should work through the OS, for example, a double-click file in Windows.
  • It should work in different JREs (Sun, IBM, OpenJDK, etc.).
  • It should not include additional encoding.
  • It should work in most library configuration files, for example, to set log4j level $ {LOG_LEVEL}.

Update : elements # 4 and 5 were added. Remove the OS from the title to make my question clearer.

Update 2 . After looking at the perception response, it seems that my points 2 and 3 can be achieved using System.getenv . How to reach points 4 and 5?

Here is an example scenario: Imagine now JAVA_DEFAULT_OPTS is an environment variable that will be considered Java, since now it has become the standard. On the development desktop machine, I set JAVA_DEFAULT_OPTS=-DLOG_LEVEL=DEBUG -Xmx384m ; On the production server server, clients set JAVA_DEFAULT_OPTS=-DLOG_LEVEL=INFO -Xmx1024m . When I / users double-click the jar file in Windows, the application will work, the log4j level and the maximum memory heap size will differ.

+6
source share
2 answers

There is a special environment variable called _JAVA_OPTIONS , its value will be picked up by the JVM (java.exe).

On Windows:

 set _JAVA_OPTIONS=-Xms64m -Xmx128m -Dawt.useSystemAAFontSettings=lcd 

On Linux:

 export _JAVA_OPTIONS='-Xms64m -Xmx128m -Dawt.useSystemAAFontSettings=lcd' 

For Java Web Run it JAVAWS_VM_ARGS . For javaw.exe (applet) it is _JPI_VM_OPTIONS .

+10
source

Java has a standard OS system environment variable that is always set when the JVM starts:

  • os.name
  • os.arch
  • os.version

All accessible through 'System.getProperty (propertyName) `

If you need something more, you can always use the management API .

+1
source

Source: https://habr.com/ru/post/910557/


All Articles