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;
}
}
I had the same exception, this is how I solved the problem:
Preconditions:
Junit class (and test), that extended another class.
ApplicationContext initialized using spring, that init the project.
The Application context was initialized in @Before method
Solution:
Init the application context from @BeforeClass method, since the parent class also required some classes that were initialized from within the application context.
Hope this will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With