问题
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)
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;
}
The environment is using,
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)
Any help would be appreciated!
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.
Thanks!
回答1:
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.
来源:https://stackoverflow.com/questions/60272893/noclassdeffounderror-being-encountered-intermittently-when-using-zonerulesprovid