如何设置java系统属性,以便每当我启动JVM而不将其添加到命令行参数时它都有效 [英] How to set a java system property so that it is effective whenever I start JVM without adding it to the command line arguments

查看:278
本文介绍了如何设置java系统属性,以便每当我启动JVM而不将其添加到命令行参数时它都有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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?

推荐答案

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

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

我使用它强制为每个JVM强制使用特定的语言环境。

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

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

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

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)

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

这篇关于如何设置java系统属性,以便每当我启动JVM而不将其添加到命令行参数时它都有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆