Default locale is reported incorrectly by non-standard Java installation.

huangapple go评论61阅读模式
英文:

Default locale is reported incorrectly by non-standard Java installation

问题

使用已安装的JDK版本时,系统默认区域设置(locale)会正确报告,但当我使用adoptopenjdk-11tar.gz版本时,它总是报告为en_US

import java.util.Locale;

public class CurrentLocale {
    public static void main(String... args) {
        System.out.println("默认区域设置(locale)为 " + Locale.getDefault());
    }
}

以下是Homebrew安装的adoptopenjdk11与下载和解压的版本之间的示例对比:

/usr/bin/java CurrentLocale
默认区域设置(locale)为 ja_JP

~/Downloads/jdk-11.0.8+10/Contents/Home/bin/java CurrentLocale
默认区域设置(locale)为 en_US

这里显示了每个JDK的版本:

# adoptopenjdk-11 (使用Homebrew安装)
/usr/bin/java -version
openjdk版本 "11.0.8" 2020-07-14
OpenJDK运行环境 AdoptOpenJDK (构建版本 11.0.8+10)
OpenJDK 64位服务器VM AdoptOpenJDK (构建版本 11.0.8+10, 混合模式)

# adoptopenjdk-11 (从https://adoptopenjdk.net/releases.html?variant=openjdk11&jvmVariant=openj9下载)
~/Downloads/jdk-11.0.8+10/Contents/Home/bin/java -version
openjdk版本 "11.0.8" 2020-07-14
OpenJDK运行环境 AdoptOpenJDK (构建版本 11.0.8+10)
Eclipse OpenJ9 VM AdoptOpenJDK (构建 openj9-0.21.0, JRE 11 Mac OS X amd64-64位 压缩引用 20200715_677 (启用JIT, 启用AOT)
OpenJ9   - 34cf4c075
OMR      - 113e54219
JCL      - 基于jdk-11.0.8+10的 95bb504fbb)

我猜想macOS可能会进行一些魔法操作,因为Java二进制文件符号链接到`/usr/bin/java`,无论Java是否已安装。

/usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

Hotspot (Oracle)版本正常工作,但openj9 (IBM)版本不起作用。

我需要将JRE捆绑到应用程序的安装程序中,并将其安装到非标准位置。

如何使下载的openj9 tar文件中的默认区域设置(locale)与当前系统的区域设置(locale)保持一致?

<details>
<summary>英文:</summary>

When using an installed version of the JDK, the default system locale is reported correctly, but when I use the `adoptopenjdk-11` `tar.gz`, it is always reported as `en_US`

    import java.util.Locale;
    
    public class CurrentLocale {
        public static void main(String... args) {
            System.out.println(&quot;Default locale &quot; + Locale.getDefault());
        }
    }


Here is an example of the Homebrew installation of `adoptopenjdk11` vs the downloaded and extracted one.

    /usr/bin/java CurrentLocale
    Default locale ja_JP

    ~/Downloads/jdk-11.0.8+10/Contents/Home/bin/java CurrentLocale
    Default locale en_US

The versions of each JDK are shown here.

    # adoptopenjdk-11 (brew cask install adoptopenjdk11)

    /usr/bin/java -version
    openjdk version &quot;11.0.8&quot; 2020-07-14
    OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
    OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)

    # adoptopenjdk-11 (Downloaded from https://adoptopenjdk.net/releases.html?variant=openjdk11&amp;jvmVariant=openj9)

    ~/Downloads/jdk-11.0.8+10/Contents/Home/bin/java -version
    openjdk version &quot;11.0.8&quot; 2020-07-14
    OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
    Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.21.0, JRE 11 Mac OS X amd64-64-Bit Compressed References 20200715_677 (JIT enabled, AOT enabled)
    OpenJ9   - 34cf4c075
    OMR      - 113e54219
    JCL      - 95bb504fbb based on jdk-11.0.8+10)

I&#39;m guessing macOS does some magic, because the Java binary symlinked to `/usr/bin/java` is always there, regardless of whether or not Java happens to be installed.

    /usr/bin/java -&gt; /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

The Hotspot (Oracle) version works fine, but the openj9 (IBM) version doesn&#39;t work.

I need to bundle the JRE in an installer with an application, and install it to a non-standard location.

How can I get the default locale in the downloaded openj9 tar to mirror the current system&#39;s locale?

</details>


# 答案1
**得分**: 1

这可能与 https://github.com/eclipse/openj9/issues/5705 有关。

<details>
<summary>英文:</summary>

I think this could be related to https://github.com/eclipse/openj9/issues/5705

</details>



huangapple
  • 本文由 发表于 2020年8月6日 08:58:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63275416.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定