I need to change the default locale that java uses on a Windows 2008 Server machine. Java is installed as part of an Oracle + Application server setup. I can do this in code, but I need to permanently change this setting.
我需要更改java在Windows 2008 Server计算机上使用的默认语言环境。 Java是作为Oracle + Application服务器设置的一部分安装的。我可以在代码中执行此操作,但我需要永久更改此设置。
Edit: I should note that we're talking about jsp pages served via Application server so I can't exactly pass command line arguments to java. Also the machine's regional and language options are already set to what I need (Greek). Java's default locale is still en_US instead of el_GR.
编辑:我应该注意,我们正在讨论通过应用程序服务器提供的jsp页面,因此我无法将命令行参数完全传递给java。机器的区域和语言选项已经设置为我需要的(希腊语)。 Java的默认语言环境仍然是en_US而不是el_GR。
Edit and solution: I was porting an existing app to a new server. The app took the default locale for granted, which didn't work out so well on the new server (it-works-on-my-machine in all its glory). I was hoping of not having to touch the code itself, but finally decided to explicitly set the default locale in-code in a file that's already included by all the pages. Not the most elegant of solutions, but wth, it works.
编辑和解决方案:我正在将现有应用移植到新服务器。该应用程序将默认语言环境视为理所当然,这在新服务器上运行得不是很好(它可以在我的机器上工作)。我希望不必触及代码本身,但最终决定在所有页面已包含的文件中明确设置in-code中的默认语言环境。不是最优雅的解决方案,但是,它确实有效。
5 个解决方案
#1
In fact there are two answers I found - the WRONG one presented by http://java.com/en/download/help/locale.xml and the hack one that works.
事实上,我找到了两个答案 - 由http://java.com/en/download/help/locale.xml提供的错误答案和有效的黑客答案。
I'll explain - I use a French-installed multi-language XP in France with a French keyboard - but I want my apps to speak to me in English. The page at Sun plain does not work with that combination - Java still talks to me in French.
我将解释 - 我在法国使用法语安装的多语言XP和法语键盘 - 但我希望我的应用程序能用英语与我交谈。 Sun平原的页面无法使用这种组合--Java仍然用法语与我交谈。
The HACK solution was to go into regedit and change HKEY_CURRENT_USER\Control Panel\International\Locale from 0000040C to 00000409. That made Java talk English.
HACK解决方案是进入注册表并将HKEY_CURRENT_USER \ Control Panel \ International \ Locale从0000040C更改为00000409.这使得Java会说英语。
Going back to the regional settings control panel tool, I noticed that this, in fact, had changed the name in the "Regional Options" drop down, while keeping all the French formatting for numbers dates etc.
回到区域设置控制面板工具,我注意到这实际上改变了“区域选项”下拉列表中的名称,同时保留了所有法语格式的数字日期等。
So that page at Sun is plain wrong!! Java does NOT get its default LOCALE from the settings on the advanced page, but from the settings on the Regional Options page - and THEY are very tough to change without screwing up ALL those options (i.e. you can't easily just change the language and leave the number/date/etc formatting as is).
所以在Sun的页面是完全错误的!! Java不会从高级页面上的设置中获取默认的LOCALE,而是从“区域选项”页面上的设置中获取 - 而且它们很难在不搞砸所有这些选项的情况下进行更改(即,您无法轻易改变语言和保留数字/日期/等格式。)
Anyone know how to get that information to Sun???
任何人都知道如何将这些信息提供给Sun ???
#2
Would specifying the locale on the command like that starts the JVM work?
在命令上指定语言环境会启动JVM工作吗?
java -Duser.language=2-char-language-code -Duser.region=2-char-country-code
java -Duser.language = 2-char-language-code -Duser.region = 2-char-country-code
http://www.oracle.com/technetwork/articles/javase/locale-140624.html
#3
For me changing the HKEY_CURRENT_USER\Control Panel\International\LocaleName
to en-US
did the trick. Changing the Locale as Martin Bartlett suggested didn't help.
对我来说,将HKEY_CURRENT_USER \ Control Panel \ International \ LocaleName更改为en-US就可以了。正如马丁巴特利特建议的那样更改区域设置没有帮助。
#4
I'm not sure how to do it with Oracle's java. Does setting the java properties user.language
, user.country
, and user.variant
work?.
我不确定如何使用Oracle的java。设置java属性user.language,user.country和user.variant是否有效?
#5
- user.language and user.country work, you can try the following examples:
user.language和user.country工作,您可以尝试以下示例:
java -Duser.language=sv -Duser.country=SE java -Duser.language=en -Duser.country=US
- If you want jvm to select it by default, you should set environment variable
JAVA_TOOL_OPTIONS
, it works on windows too (except that setting environment variable is a little different on windows)!
如果你想让jvm默认选择它,你应该设置环境变量JAVA_TOOL_OPTIONS,它也适用于Windows(除了设置环境变量在windows上有点不同)!
export JAVA_TOOL_OPTIONS="-Duser.language=en -Duser.country=US"
Please refer to this question for details of JAVA_TOOL_OPTIONS.
有关JAVA_TOOL_OPTIONS的详细信息,请参阅此问题。
#1
In fact there are two answers I found - the WRONG one presented by http://java.com/en/download/help/locale.xml and the hack one that works.
事实上,我找到了两个答案 - 由http://java.com/en/download/help/locale.xml提供的错误答案和有效的黑客答案。
I'll explain - I use a French-installed multi-language XP in France with a French keyboard - but I want my apps to speak to me in English. The page at Sun plain does not work with that combination - Java still talks to me in French.
我将解释 - 我在法国使用法语安装的多语言XP和法语键盘 - 但我希望我的应用程序能用英语与我交谈。 Sun平原的页面无法使用这种组合--Java仍然用法语与我交谈。
The HACK solution was to go into regedit and change HKEY_CURRENT_USER\Control Panel\International\Locale from 0000040C to 00000409. That made Java talk English.
HACK解决方案是进入注册表并将HKEY_CURRENT_USER \ Control Panel \ International \ Locale从0000040C更改为00000409.这使得Java会说英语。
Going back to the regional settings control panel tool, I noticed that this, in fact, had changed the name in the "Regional Options" drop down, while keeping all the French formatting for numbers dates etc.
回到区域设置控制面板工具,我注意到这实际上改变了“区域选项”下拉列表中的名称,同时保留了所有法语格式的数字日期等。
So that page at Sun is plain wrong!! Java does NOT get its default LOCALE from the settings on the advanced page, but from the settings on the Regional Options page - and THEY are very tough to change without screwing up ALL those options (i.e. you can't easily just change the language and leave the number/date/etc formatting as is).
所以在Sun的页面是完全错误的!! Java不会从高级页面上的设置中获取默认的LOCALE,而是从“区域选项”页面上的设置中获取 - 而且它们很难在不搞砸所有这些选项的情况下进行更改(即,您无法轻易改变语言和保留数字/日期/等格式。)
Anyone know how to get that information to Sun???
任何人都知道如何将这些信息提供给Sun ???
#2
Would specifying the locale on the command like that starts the JVM work?
在命令上指定语言环境会启动JVM工作吗?
java -Duser.language=2-char-language-code -Duser.region=2-char-country-code
java -Duser.language = 2-char-language-code -Duser.region = 2-char-country-code
http://www.oracle.com/technetwork/articles/javase/locale-140624.html
#3
For me changing the HKEY_CURRENT_USER\Control Panel\International\LocaleName
to en-US
did the trick. Changing the Locale as Martin Bartlett suggested didn't help.
对我来说,将HKEY_CURRENT_USER \ Control Panel \ International \ LocaleName更改为en-US就可以了。正如马丁巴特利特建议的那样更改区域设置没有帮助。
#4
I'm not sure how to do it with Oracle's java. Does setting the java properties user.language
, user.country
, and user.variant
work?.
我不确定如何使用Oracle的java。设置java属性user.language,user.country和user.variant是否有效?
#5
- user.language and user.country work, you can try the following examples:
user.language和user.country工作,您可以尝试以下示例:
java -Duser.language=sv -Duser.country=SE java -Duser.language=en -Duser.country=US
- If you want jvm to select it by default, you should set environment variable
JAVA_TOOL_OPTIONS
, it works on windows too (except that setting environment variable is a little different on windows)!
如果你想让jvm默认选择它,你应该设置环境变量JAVA_TOOL_OPTIONS,它也适用于Windows(除了设置环境变量在windows上有点不同)!
export JAVA_TOOL_OPTIONS="-Duser.language=en -Duser.country=US"
Please refer to this question for details of JAVA_TOOL_OPTIONS.
有关JAVA_TOOL_OPTIONS的详细信息,请参阅此问题。