【问题标题】:NoClassDefFoundError Being Encountered Intermittently When Using ZoneRulesProvider使用 ZoneRulesProvider 时间歇性遇到 NoClassDefFoundError
【发布时间】:2020-02-18 02:23:40
【问题描述】:

我知道这与question 有点相似,但那里的答案似乎对我没有帮助。但是我也遇到了同样的问题..这是日志的sn-p,

java.lang.NoClassDefFoundError: Could not initialize class 
java.time.zone.ZoneRulesProvider
java.time.ZoneRegion.ofId(ZoneRegion.java:120)
java.time.ZoneId.of(ZoneId.java:411)
java.time.ZoneId.of(ZoneId.java:359)
java.time.ZoneId.of(ZoneId.java:315)
java.util.TimeZone.toZoneId(TimeZone.java:556)
java.time.ZoneId.systemDefault(ZoneId.java:274)

它似乎来自于在我的实用程序方法中使用 ZoneId.systemDefault(),

    public  static String formatDate(Date date) {
        if(Objects.nonNull(date)) {
            LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            return localDate.format(<some_formats_here>);
        }

        return null;
    }

环境正在使用,

openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

任何帮助将不胜感激!

顺便说一下,这会间歇性地发生,并且会在将最新代码部署到服务器后发生。即使环境设置与生产环境相同,我在本地机器的构建中也没有遇到过。

谢谢!

【问题讨论】:

    标签: noclassdeffounderror


    【解决方案1】:

    据我的同事说,JVM_HOME 必须在系统级别声明。这部分代码是问题所在:

    try {
                String libDir = System.getProperty("java.home") + File.separator + "lib";
                try (DataInputStream dis = new DataInputStream(
                         new BufferedInputStream(new FileInputStream(
                             new File(libDir, "tzdb.dat"))))) {
                    load(dis);
                }
            } catch (Exception ex) {
                throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex);
            }
    

    不幸的是,我无法详细说明它是如何真正解决的,但到目前为止它对我们有用。可能会帮助其他人。

    【讨论】:

      猜你喜欢
      • 2020-10-20
      • 1970-01-01
      • 2020-12-01
      • 2020-10-26
      • 1970-01-01
      • 1970-01-01
      • 2017-07-22
      • 2015-01-29
      • 1970-01-01
      相关资源
      最近更新 更多