public static ClassLoader findMostCompleteClassLoader ( Class < ? > target ) { // Try the most complete class loader we can get ClassLoader classLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; // Then fallback to the class loader from a specific class given if ( classLoader == null && target != null ) { classLoader = target . getClassLoader ( ) ; } // Then fallback to the class loader that loaded this class if ( classLoader == null ) { classLoader = ClassLoaders . class . getClassLoader ( ) ; } // Then fallback to the system class loader if ( classLoader == null ) { classLoader = ClassLoader . getSystemClassLoader ( ) ; } // Throw an exception if no classloader was found at all if ( classLoader == null ) { throw new RuntimeException ( "Unable to find a classloader" ) ; } return classLoader ; }
Find the most complete class loader by trying the current thread context class loader then the classloader of the given class if any then the class loader that loaded SEED core then the system class loader .