GraalVM native-image Java i18n Locale问题

huangapple 未分类评论48阅读模式
英文:

GraalVM native-image Java i18n Locale problem

问题

我尝试使用Locale创建一个程序。我想使用GraalVM本地编译此程序,但是在本地编译后,Locale的行为不同。

我通过以下程序成功地分离出了问题:

  1. import java.text.NumberFormat;
  2. import java.util.Locale;
  3. import java.util.Currency;
  4. public class HelloWorld {
  5. public static void main(String[] args) {
  6. NumberFormat gbNumberFormat = NumberFormat.getCurrencyInstance(new Locale("en", "GB"));
  7. gbNumberFormat.setCurrency(Currency.getInstance("USD"));
  8. System.out.println(gbNumberFormat.format(1337));
  9. NumberFormat usNumberFormat = NumberFormat.getCurrencyInstance(new Locale("en", "US"));
  10. usNumberFormat.setCurrency(Currency.getInstance("USD"));
  11. System.out.println(usNumberFormat.format(1337));
  12. }
  13. }

我可以在Java中编译此程序:

  1. javac -d out/ HelloWorld.java

然后执行它(从out目录):

  1. java HelloWorld

结果是:

  1. US$1,337.00
  2. $1,337.00

我现在可以制作本地镜像并运行它:

  1. native-image -cp out/ HelloWorld
  2. ./helloworld

结果不同:

  1. $1,337.00
  2. $1,337.00

在本地模式下,我似乎遇到了国际化问题。我不太理解为什么会出现这种情况。我使用的是graalvm-ce-java11-20.0.0,但我测试了之前的版本,行为相同。

如果有需要,我随时为您提供帮助。

英文:

I try to make a program using Locale. I want compile natively this program with GraalVM but Locale don't have the same behavior after native compiling.

I success to isolate the problem with the following program :

  1. import java.text.NumberFormat;
  2. import java.util.Locale;
  3. import java.util.Currency;
  4. public class HelloWorld {
  5. public static void main(String[] args) {
  6. NumberFormat gbNumberFormat = NumberFormat.getCurrencyInstance(new Locale("en", "GB"));
  7. gbNumberFormat.setCurrency(Currency.getInstance("USD"));
  8. System.out.println(gbNumberFormat.format(1337));
  9. NumberFormat usNumberFormat = NumberFormat.getCurrencyInstance(new Locale("en", "US"));
  10. usNumberFormat.setCurrency(Currency.getInstance("USD"));
  11. System.out.println(usNumberFormat.format(1337));
  12. }
  13. }

I can compile this program in Java :

  1. javac -d out/ HelloWorld.java

And execute it (from out directory) :

  1. java HelloWorld

The result is :

  1. US$1,337.00
  2. $1,337.00

I can now make the native image and launch it :

  1. native-image -cp out/ HelloWorld
  2. ./helloworld

The result is not the same :

  1. $1,337.00
  2. $1,337.00

It is look likes I have a problem with i18n in native mode. I don't really understand why.
I am using graalvm-ce-java11-20.0.0 but I tested with previous versions with same behavior.

I am at your disposal if necessary.

huangapple
  • 本文由 发表于 2020年5月4日 12:37:56
  • 转载请务必保留本文链接:https://java.coder-hub.com/61585274.html
匿名

发表评论

匿名网友

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

确定