Java Class Loader print(ClassLoader loader)

Here you can find the source of print(ClassLoader loader)

Description

print

License

Open Source License

Declaration

public static void print(ClassLoader loader) 

Method Source Code

//package com.java2s;
/**/*from   ww  w .  j av a  2s. co  m*/
 * $Header: /home/master/nWave-DM-Common/src/com/npower/dm/util/DMUtil.java,v 1.6 2007/08/29 06:21:00 zhao Exp $
 * $Revision: 1.6 $
 * $Date: 2007/08/29 06:21:00 $
 *
 * ===============================================================================================
 * License, Version 1.1
 *
 * Copyright (c) 1994-2006 NPower Network Software Ltd.  All rights reserved.
 *
 * This SOURCE CODE FILE, which has been provided by NPower as part
 * of a NPower product for use ONLY by licensed users of the product,
 * includes CONFIDENTIAL and PROPRIETARY information of NPower.
 *
 * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
 * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
 * THE PRODUCT.
 *
 * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD NPower, ITS RELATED
 * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
 * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
 * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
 * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
 * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
 * CODE FILE.
 * ===============================================================================================
 */

import java.lang.reflect.Method;
import java.net.URL;

public class Main {
    public static void print(ClassLoader loader) {
        System.out.println("Dump classload: " + loader.toString());
        URL[] urls = getClassLoaderURLs(loader);
        for (int i = 0; urls != null && i < urls.length; i++) {
            System.out.println(urls[i].toString());
        }
        System.out.println("End of classload: " + loader.toString());
    }

    /**
     * Use reflection to access a URL[] getURLs or ULR[] getAllURLs method so that
     * non-URLClassLoader class loaders, or class loaders that override getURLs to
     * return null or empty, can provide the true classpath info.
     */
    public static URL[] getClassLoaderURLs(ClassLoader cl) {
        URL[] urls = {};
        try {
            Class<?> returnType = urls.getClass();
            Class<?>[] parameterTypes = {};
            Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes);
            if (returnType.isAssignableFrom(getURLs.getReturnType())) {
                Object[] args = {};
                urls = (URL[]) getURLs.invoke(cl, args);
            }
        } catch (Exception ignore) {
        }
        return urls;
    }
}

Related

  1. loadManifestFrom(Class c)
  2. loadProperties(final Properties properties, final String fileName, final ClassLoader cl)
  3. loadStyleSheet(Class type)
  4. loadTextFile(Class relToThisClass, String relFileName)
  5. pathFromLoaders(final Class clazz)
  6. readAll(ClassLoader cl, String path)
  7. readBytecodeForClass(ClassLoader loader, String className, boolean mustExist)
  8. resolveClientClassLoader(Map env)
  9. resolveServerClassLoader(Map env, MBeanServer mbs)