Reputation: 1139
I use Grails 2.2.3. I have put jar file in lib directory, IDEA immediately resolved the dependency. But when I start app I get NullPointerException
on class from this library. If I try it second time or more I get java.lang.NoClassDefFoundError
. I found a lot of advice how to resolve this issue but none were useful in my case.
Library (mylib-1.jar
) compiled in maven and added to lib dir. In BuildConfig.groovy
, dependency is mentioned as:
dependencies {
compile 'com.mylib:mylib:1'
}
I tried
grails clean
grails compile --refresh-dependencies
grails refresh-dependencies
but nothing helps. In result war file I can see this library in WEB-INF/lib, but even if deploy this war I get the same error.
How can this be resolved?
Upvotes: 0
Views: 1254
Reputation: 75671
You're confusing NoClassDefFoundError
with ClassNotFoundException
. ClassNotFoundException
happens when a class you want isn't there, but you get a NoClassDefFoundError
when the class is there, but a class it depends on isn't. So you're missing another jar file that this jar file depends on.
This is one of the many reasons why it's best to use dependency management instead of manually copying jar files to the lib directory. If you use a Maven repo where the jars have proper POM files, their dependencies are specified, and the resolver can download the entire tree of dependencies for you, rather than you having to find all of the jars yourself.
Upvotes: 3