How to set a java system property so that it is effective whenever I start JVM without adding it to the command line arguments

后端 未结 1 1474
暗喜
暗喜 2020-12-01 02:01

There was a change in Java 1.7 in the way the default Locale is get from the OS. There are methods of restoring the old behaviour e.g. by setting the flag -Dsun.locale.forma

相关标签:
1条回答
  • 2020-12-01 02:29

    You can set set environment variable JAVA_TOOL_OPTIONS in your OS. All Java tools (java, javac, ..) will pick this variable up and use it. So you could e.g. use

    SET JAVA_TOOL_OPTIONS=-Dsun.locale.formatasdefault=true
    

    I use this to force a specific locale for each JVM.

    But this only works if your application is started through the Java tools. If it is e.g. started from a C program that calls the jvm DLL this won't be used.

    Edit: I just tested it, and it seems JAVA_TOOLS_OPTIONS is also picked up when the DLLs are started (verified with a Swing application that uses WinRun4J as a launcher)

    See: http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/envvars.html

    0 讨论(0)
提交回复
热议问题