使用ZoneRulesProvider时间歇性遇到NoClassDefFoundError [英] NoClassDefFoundError Being Encountered Intermittently When Using ZoneRulesProvider

查看:615
本文介绍了使用ZoneRulesProvider时间歇性遇到NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这在某种程度上类似于问题,但那里的答案似乎对我没有帮助.但是我也遇到了同样的问题..这是日志的片段,

I know that this is somehow similar to this question, but the answer there doesn't seem to help me. But I am also encountering the same issue.. here's a snippet of the logs,

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()而引起的,

And it seems like it's coming from using ZoneId.systemDefault() in my utility method,

    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)

任何帮助将不胜感激!

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

By the way, this occurs intermittently and happens after deploying the latest codes to the server. I have not encountered it in my local machine's build even though the environment set up are the same with production environment.

谢谢!

推荐答案

结果表明,根据我的同事,必须在系统级别上声明JVM_HOME.这部分代码是解决问题的一个方法:

Turns out that JVM_HOME must be declared on a system level according to my colleague. This part of code was the one spitting up the problem:

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);
        }

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

Unfortunately I can't really elaborate on how it was really solved but so far it worked for us. Might help others.

这篇关于使用ZoneRulesProvider时间歇性遇到NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆