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

查看:878
本文介绍了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文件时,jar tf myjarfile ,我可以看到那里列出的 PropHolder.class

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

Btw:我的代码运行正常本地机器。但是当我将一些脚本部署到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天全站免登陆