9

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?

Tom Sebastian
  • 3,373
  • 5
  • 29
  • 54

1 Answers1

12

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

enter image description here

C:> set _JAVA_OPTIONS=-Dfile.encoding=UTF-8
C:> javaw com.example.PropertyTest

enter image description here

By setting the environment variable as a system environment variable, it applies to all java processes.

See also

Community
  • 1
  • 1
Andreas Fester
  • 36,091
  • 7
  • 95
  • 123