如何设置java系统属性,以便每当我启动JVM而不将其添加到命令行参数时它都有效

时间:2021-04-26 17:21:28

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.formatasdefault=true when starting a JVM instance.

Java 1.7的默认Locale从操作系统获得的方式发生了变化。有一些方法可以恢复旧的行为,例如通过在启动JVM实例时设置标志-Dsun.locale.formatasdefault = true。

I would like to set this flag permanently so that I don't have to specify it in command line arguments each time when I start a JVM instance. Is there a file or any other possibility to change the default settings for JVM? Something like the Eclipse.ini file but for the JVM itself?

我想永久设置这个标志,这样我每次启动JVM实例时都不必在命令行参数中指定它。是否有文件或任何其他可能更改JVM的默认设置?类似于Eclipse.ini文件但是对于JVM本身?

1 个解决方案

#1


41  

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

您可以在操作系统中设置设置环境变量JAVA_TOOL_OPTIONS。所有Java工具(java,javac,..)都将选择此变量并使用它。所以你可以,例如使用

SET JAVA_TOOL_OPTIONS=-Dsun.locale.formatasdefault=true

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

我使用它来强制每个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.

但这仅适用于通过Java工具启动应用程序的情况。如果它是例如从一个调用jvm DLL的C程序开始,这将不会被使用。

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)

编辑:我刚刚测试了它,似乎JAVA_TOOLS_OPTIONS也在DLL启动时被拾取(使用WinRun4J作为启动器的Swing应用程序验证)

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

#1


41  

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

您可以在操作系统中设置设置环境变量JAVA_TOOL_OPTIONS。所有Java工具(java,javac,..)都将选择此变量并使用它。所以你可以,例如使用

SET JAVA_TOOL_OPTIONS=-Dsun.locale.formatasdefault=true

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

我使用它来强制每个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.

但这仅适用于通过Java工具启动应用程序的情况。如果它是例如从一个调用jvm DLL的C程序开始,这将不会被使用。

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)

编辑:我刚刚测试了它,似乎JAVA_TOOLS_OPTIONS也在DLL启动时被拾取(使用WinRun4J作为启动器的Swing应用程序验证)

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