设置 Java 语言环境设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/64038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting java locale settings
提问by
When I use the default java locale on my linux machine it comes out with the US locale settings, where do I change this so that it comes out with the correct locale?
当我在我的 linux 机器上使用默认的 java 语言环境时,它带有美国语言环境设置,我应该在哪里更改它以使其具有正确的语言环境?
采纳答案by pjz
I believe java gleans this from the environment variables in which it was launched, so you'll need to make sure your LANG and LC_* environment variables are set appropriately.
我相信 java 从启动它的环境变量中收集到这一点,因此您需要确保正确设置了 LANG 和 LC_* 环境变量。
The locale manpagehas full info on said environment variables.
语言环境联机帮助页包含有关所述环境变量的完整信息。
回答by sblundy
You could call during init or whatever Locale.setDefault()or -Duser.language=, -Duser.country=, and -Duser.variant= at the command line. Here's something on Sun's site.
您可以在 init 或任何Locale.setDefault()或 -Duser.language=、-Duser.country= 和 -Duser.variant= 期间在命令行调用。这是 Sun 网站上的一些内容。
回答by killdash10
One way to control the locale settings is to set the java system properties user.language and user.region.
控制区域设置的一种方法是设置 java 系统属性 user.language 和 user.region。
回答by Chris Broadfoot
With the user.language
, user.country
and user.variant
properties.
与user.language
,user.country
和user.variant
属性。
Example:
例子:
java -Duser.language=th -Duser.country=TH -Duser.variant=TH SomeClass
java -Duser.language=th -Duser.country=TH -Duser.variant=TH SomeClass
回答by Gmu
If you are on Mac, simply using System Preferences -> Languages and dragging the language to test to top (before English) will make sure the next time you open the App, the right locale is tried!!
如果您使用的是 Mac,只需使用 System Preferences -> Languages 并将要测试的语言拖到顶部(在英语之前)将确保您下次打开应用程序时尝试正确的语言环境!!
回答by cayhorstmann
I had to control this in a script that ran on a machine with French locale, but a specific Java program had to run with en_US. As already pointed out, the following works:
我必须在使用法语语言环境的机器上运行的脚本中控制它,但特定的 Java 程序必须使用 en_US 运行。正如已经指出的,以下工作:
java -Duser.language=en -Duser.country=US ...
Alternatively,
或者,
LC_ALL=en_US.UTF-8 java ...
I prefer the latter.
我更喜欢后者。
回答by Derzu
You can change on the console:
您可以在控制台上更改:
$ export LANG=en_US.utf8
回答by hiroshi
For tools like jarsigner
which is implemented in Java.
对于像jarsigner
在 Java 中实现的工具。
JAVA_TOOL_OPTIONS=-Duser.language=en jarsigner
回答by aseychell
On linux, create file in /etc/default/locale
with the following contents
在linux上,/etc/default/locale
使用以下内容创建文件
LANG=en.utf8
and then use the source
command to export this variable by running
然后使用source
命令通过运行导出此变量
source /etc/default/locale
The source command sets the variable permanently.
source 命令永久设置变量。
回答by Matthew Buckett
If you ever want to check what locale or character set java is using this is built into the JVM:
如果您想检查 java 正在使用的语言环境或字符集,这内置于 JVM 中:
java -XshowSettings -version
and it will dump out loads of the settings it's using. This way you can check your LANG
and LC_*
values are getting picked up correctly.
它会转储它正在使用的设置的负载。通过这种方式,您可以检查您的LANG
和LC_*
值是否被正确提取。