Is there any way to set certain properties that will be applicable for all java processes(java.exe
,javaw.exe
for windows) running on that machine ?
More clearly suppose I want to use a specific timezone to be applied for all java processes running in that machine(without changing the system timezone).
I know we can pass it as -D
argument, but it will be applicable only for that java process right.But I need it in the other way- for every java process started.
Is there any way to do that?
System properties are set on the Java command line using the -Dpropertyname=value syntax. They can also be added at runtime using System. setProperty(String key, String value) or via the various System. getProperties().
The directory server provides a means of configuring the Java Virtual Machine (JVM) and Java options for each command-line utility and for the directory server itself. The Java configuration is provided in a properties file, located at instance-dir /OUD/config/java.
You can determine the properties and variables of your JVM by determining the process id of java (ps -ef, jps, or task manager), cd'ing to $JAVA_HOME/bin directory, then running jinfo <process id> . Of course you can use grep to find a specific property.
Tried with Java 8:
You can use the environment variable _JAVA_OPTIONS
to specify default parameters for java.exe
and javaw.exe
, for example
C:> set _JAVA_OPTIONS=-Dfile.encoding=UTF-8
Quick and dirty test for javaw
:
package com.example;
import javax.swing.JFrame;
import javax.swing.JTextPane;
public class PropertyTest {
public static void main(String[] args) {
String value = (String) System.getProperties().get("file.encoding");
JTextPane txt = new JTextPane();
txt.setText(value);
JFrame main = new JFrame();
main.add(txt);
main.setVisible(true);
}
}
C:> javaw com.example.PropertyTest
C:> set _JAVA_OPTIONS=-Dfile.encoding=UTF-8
C:> javaw com.example.PropertyTest
By setting the environment variable as a system environment variable, it applies to all java processes.
See also
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