java.lang.NoClassDefFoundError: Could not initialize class XXX java.lang.NoClassDefFoundError: Could not initialize class XXX java java

java.lang.NoClassDefFoundError: Could not initialize class XXX


My best bet is there is an issue here:

static {    //code for loading properties from file}

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.

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


You are getting a java.lang.NoClassDefFoundError which does NOT mean that your class is missing (in that case you'd get a java.lang.ClassNotFoundException). The ClassLoader ran into an error while reading the class definition when trying to read the class.

Put a try/catch inside your static initializer and look at the exception. If you read some files there and it differs from your local environment it's very likely the cause of the problem (maybe file can't be found, no permissions etc.).


NoClassDefFoundError doesn't give much of a clue as to what went wrong inside the static block. It is good practice to always have a block like this inside of static { ... } initialization code:

static {  try {    ... your init code here  } catch (Throwable t) {    LOG.error("Failure during static initialization", t);    throw t;  }}