jar – java.lang.NoClassDefFoundError: Could not initialize class XXX
jar – 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 youd 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 its very likely the cause of the problem (maybe file cant be found, no permissions etc.).
jar – java.lang.NoClassDefFoundError: Could not initialize class XXX
NoClassDefFoundError doesnt 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;
}
}