java.lang.NoClassDefFoundError: 无法初始化类 XXX [英] java.lang.NoClassDefFoundError: Could not initialize class XXX

查看:46
本文介绍了java.lang.NoClassDefFoundError: 无法初始化类 XXX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class PropHolder {
  public static Properties prop;

  static {
    //code for loading properties from file
  }
}

// Referencing the class somewhere else:
Properties prop = PropHolder.prop;

class PropHolder 是我自己的一个类.该类位于主类的同一个 JAR 文件中.所以这不应该是因为类路径中缺少任何 JAR.

class PropHolder is a class of my own. The class resides in the same JAR file of the main class. So that should not because any JAR is missing from classpath.

当我通过 jar tf myjarfile 查看 JAR 文件时,我可以看到其中列出的 PropHolder.class.

When I look in to the JAR file by jar tf myjarfile, I can see the PropHolder.class listed there.

顺便说一句:代码在我的本地机器上运行良好.但是当我用一些脚本将它部署到 Linux 服务器上时无法工作.所以我认为这不是代码的问题.但出于某种原因.部署过程很难跟踪.

Btw: the code is running fine on my local machine. But couldn't work when I deploy it with some script onto a Linux server. So I think it is not the problem of the code. But for some reason. the deploy process is very hard to track.

可能是什么问题?

推荐答案

我最好的办法是这里有问题:

My best bet is there is an issue here:

static {
    //code for loading properties from file
}

似乎发生了一些未捕获的异常,并传播到尝试加载类的实际 ClassLoader.不过,我们需要一个堆栈跟踪来确认这一点.

It would appear some uncaught exception occurred and propagated up to the actual ClassLoader attempting to load the class. We would need a stacktrace to confirm this though.

在创建 PropHolder.prop 静态变量时发生.

Either that or it occurred when creating PropHolder.prop static variable.

这篇关于java.lang.NoClassDefFoundError: 无法初始化类 XXX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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