Globally Configurable Properties for the JVM

Is there a way to set certain properties that will be applicable to all java processes ( java.exe, javaw.exefor windows) running on this machine?

More clearly, I want to use a specific time zone for all java processes running on this machine (without changing the system time zone).

I know that we can pass it as an argument -D, but it will only apply to this java process. But I need it in a different way - for every Java process.

Is there any way to do this?

+4
source share
1 answer

Tried with Java 8:

_JAVA_OPTIONS java.exe javaw.exe,

C:> set _JAVA_OPTIONS=-Dfile.encoding=UTF-8

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

, java-.

.

+4

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


All Articles