如何在 Windows 上永久更改 java 的默认区域设置

发布于 2024-07-26 20:21:24 字数 416 浏览 9 评论 0原文

我需要更改 java 在 Windows 2008 Server 计算机上使用的默认区域设置。 Java 作为 Oracle + 应用程序服务器设置的一部分进行安装。 我可以在代码中执行此操作,但我需要永久更改此设置。

编辑:我应该注意,我们正在讨论通过应用程序服务器提供的 jsp 页面,因此我无法准确地将命令行参数传递给 java.js。 此外,机器的区域和语言选项已经设置为我需要的(希腊语)。 Java 的默认区域设置仍然是 en_US 而不是 el_GR。

编辑和解决方案:我正在将现有应用程序移植到新服务器。 该应用程序将默认区域设置视为理所当然,这在新服务器上运行得不太好(它在我的机器上运行得很好)。 我希望不必触及代码本身,但最终决定在所有页面已包含的文件中显式设置代码中的默认区域设置。 这不是最优雅的解决方案,但它确实有效。

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.

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

羁绊已千年 2024-08-02 20:21:24

像这样在命令上指定区域设置会启动 JVM 工作吗?

java -Duser.language=2-char-language-code -Duser.region=2-char-country-code

http://www.oracle.com/technetwork/articles/javase/locale-140624.html

Would specifying the locale on the command like that starts the JVM work?

java -Duser.language=2-char-language-code -Duser.region=2-char-country-code

http://www.oracle.com/technetwork/articles/javase/locale-140624.html

单调的奢华 2024-08-02 20:21:24

事实上,我发现了两个答案 - http://java.com 提出的错误答案/en/download/help/locale.xml 以及有效的 hack 方法。

我会解释一下 - 我在法国使用法语安装的多语言 XP 和法语键盘 - 但我希望我的应用程序能用英语与我对话。 Sun plain 的页面不适用于该组合 - Java 仍然用法语与我对话。

HACK 解决方案是进入 regedit 并将 HKEY_CURRENT_USER\Control Panel\International\Locale 从 0000040C 更改为 00000409。这使得 Java 可以说英语。

回到区域设置控制面板工具,我注意到,事实上,这已经更改了“区域选项”下拉列表中的名称,同时保留了数字日期等的所有法语格式。

因此,Sun 的页面是完全错误的!! Java 不会从高级页面上的设置中获取默认的 LOCALE,而是从区域选项页面上的设置中获取默认的 LOCALE,并且如果不搞砸所有这些选项,则很难更改它们(即,您不能轻松地仅更改语言和保留数字/日期/等格式不变)。

有人知道如何将这些信息提供给 Sun 吗???

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.

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.

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.

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).

Anyone know how to get that information to Sun???

谎言 2024-08-02 20:21:24

对我来说,将 HKEY_CURRENT_USER\Control Panel\International\LocaleName 更改为 en-US 就成功了。 按照 Martin Bartlett 的建议更改区域设置没有帮助。

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.

提赋 2024-08-02 20:21:24
  1. user.language 和 user.country 工作,你可以尝试以下示例:
    java -Duser.language=sv -Duser.country=SE
    java -Duser.language=en -Duser.country=US

  1. 如果你想让jvm默认选择它,你应该设置环境变量JAVA_TOOL_OPTIONS它也适用于Windows(除了Windows 上的设置环境变量有点不同)
    export JAVA_TOOL_OPTIONS="-Duser.language=en -Duser.country=US"

请参阅此问题以了解 JAVA_TOOL_OPTIONS 的详细信息

  1. user.language and user.country work, you can try the following examples:
    java -Duser.language=sv -Duser.country=SE
    java -Duser.language=en -Duser.country=US

  1. 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)!
    export JAVA_TOOL_OPTIONS="-Duser.language=en -Duser.country=US"

Please refer to this question for details of JAVA_TOOL_OPTIONS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文