public static String getUserCodeClassLoaderInfo ( ClassLoader loader ) { if ( loader instanceof URLClassLoader ) { URLClassLoader cl = ( URLClassLoader ) loader ; try { StringBuilder bld = new StringBuilder ( ) ; if ( cl == ClassLoader . getSystemClassLoader ( ) ) { bld . append ( "System ClassLoader: " ) ; } else { bld . append ( "URL ClassLoader:" ) ; } for ( URL url : cl . getURLs ( ) ) { bld . append ( "\n " ) ; if ( url == null ) { bld . append ( "(null)" ) ; } else if ( "file" . equals ( url . getProtocol ( ) ) ) { String filePath = url . getPath ( ) ; File fileFile = new File ( filePath ) ; bld . append ( "file: '" ) . append ( filePath ) . append ( ' ' ) ; if ( fileFile . exists ( ) ) { if ( fileFile . isDirectory ( ) ) { bld . append ( " (directory)" ) ; } else { JarFile jar = null ; try { jar = new JarFile ( filePath ) ; bld . append ( " (valid JAR)" ) ; } catch ( Exception e ) { bld . append ( " (invalid JAR: " ) . append ( e . getMessage ( ) ) . append ( ' ' ) ; } finally { if ( jar != null ) { jar . close ( ) ; } } } } else { bld . append ( " (missing)" ) ; } } else { bld . append ( "url: " ) . append ( url ) ; } } return bld . toString ( ) ; } catch ( Throwable t ) { return "Cannot access classloader info due to an exception.\n" + ExceptionUtils . stringifyException ( t ) ; } } else { return "No user code ClassLoader" ; } }
Gets information about URL class loaders . The returned info string contains all URLs of the class loader . For file URLs it contains in addition whether the referenced file exists is a valid JAR file or is a directory .