JgSudhakar
JgSudhakar

Reputation: 55

NoClassDefFoundError: in Web Sphere liberty Profile

I have deployed the one ear inside the dropins folder and one of the war file from the ear is referencing the jar which i kept outside folder (Shared->config->lib->global). External jars which i kept global folder is again referring few jar which resides in the ear and this time i am getting "java.lang.NoClassDefFoundError"

Can you please suggest how to give reference .

server.xml

<webApplication contextRoot="/xyz" id="zyx" location="xyz.ear" name="xyz" type="ear">
<classloader commonLibraryRef="global,filterjars"></classloader>
</webApplication>

Upvotes: 0

Views: 988

Answers (1)

Andy McCright
Andy McCright

Reputation: 1283

Common shared libraries cannot load classes from application binaries. When using common libraries, you can think of them as a one-way connection. The application's classloader can delegate to common shared libraries, but not the other way around.

Common libraries are implemented as their own classloader so they must contain all dependencies.

On the other hand, private libraries have their classpaths appended to the application classloader's classpath - so they could load classes provided by the application, but this is not a good practice. For example, if a private library depends on ClassA that application1 provides, it will work just fine for application1, but might break in application2 that might not provide ClassA (or might provide an incompatible version of it).

If you have classes in your shared libraries that depend on classes in your application, I would either recommend putting all of those classes in the shared library - or putting all of the shared library classes in the application (or WAR, etc.). I personally prefer the latter - self-contained applications are much more portable and less likely to run into classloader/dependency issues (i.e. app1 needs version X of some dependency, but app2 needs need version X+5...).

Hope this helps, Andy

Upvotes: 1

Related Questions