Here you can find the source of print(ClassLoader loader)
public static void print(ClassLoader loader)
//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; } }