Eclipse: Run => NoClassDefFoundError for an interface when loading a class implementing it

I had quite a hard time trying to run the following code in Eclipse (CollectionUserType implements UserType):

The problem was:

Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/hibernate/UserType
    at java.lang.ClassLoader.findBootstrapClass(Native Method)
    at java.lang.ClassLoader.findBootstrapClass0(
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(

The strange thing was that I could define instances of both UserType and CollectionUserType so it was clear that the classes are available. The evident conclusion was that CollectionUserType  is loaded by a special classloader that doesn't have access to UserType.

Examining closely the Run Configuration I've discovered the cause: the location of CollectionUserType was among the Bootstrap Entries while the location of UserType was among User Entries. And since the bootstrap class loader is above other class loaders in the class loader hierarchy, it has no access to classes loaded by the subordinate class loaders (including UserType) while vice versa it's all right.<

So the solution was to move the entry from Bootstrap Entries to User Entries.

Tags: java

Copyright © 2024 Jakub Holý
Powered by Cryogen
Theme by KingMob