public static URL getDeepResource ( ClassLoader startLoader , String resourceName ) { ClassLoader currentLoader = checkNotNull ( startLoader ) ; URL url = currentLoader . getResource ( checkNotEmpty ( resourceName ) ) ; int attempts = 0 ; while ( url == null && attempts < 10 ) { // search the class loader tree currentLoader = currentLoader . getParent ( ) ; attempts += 1 ; //no inspection ConstantConditions if ( currentLoader == null ) { break ; // we are at the bootstrap class loader } url = currentLoader . getResource ( resourceName ) ; } checkArgument ( url != null , "resource %s not found for the context class loader %s" , resourceName , startLoader ) ; return url ; }
Search class loader tree for resource current implementation attempts up to 10 levels of nested class loaders .