Java Class Loader getClassLoaderStack(ClassLoader cl)

Here you can find the source of getClassLoaderStack(ClassLoader cl)

Description

Get all of the URLClassLoaders from cl on up the hierarchy

License

Open Source License

Parameter

Parameter Description
cl the class loader to start from

Return

The possibly empty array of URLClassLoaders from cl through its parent class loaders

Declaration

public static URLClassLoader[] getClassLoaderStack(ClassLoader cl) 

Method Source Code

//package com.java2s;
/*//from   w  ww.  j  a  v  a 2s . c o m
 * JBoss, Home of Professional Open Source.
 * Copyright 2006, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.net.URLClassLoader;

import java.util.ArrayList;

public class Main {
    /** Get all of the URLClassLoaders from cl on up the hierarchy
     *
     * @param cl the class loader to start from
     * @return The possibly empty array of URLClassLoaders from cl through
     *    its parent class loaders
     */
    public static URLClassLoader[] getClassLoaderStack(ClassLoader cl) {
        ArrayList stack = new ArrayList();
        while (cl != null) {
            if (cl instanceof URLClassLoader) {
                stack.add(cl);
            }
            cl = cl.getParent();
        }
        URLClassLoader[] ucls = new URLClassLoader[stack.size()];
        stack.toArray(ucls);
        return ucls;
    }
}

Related

  1. getClassLoader(String path)
  2. getClassLoaderForClass(final Class clazz)
  3. getClassLoaderForDirectory(final File baseFolder)
  4. getClassloaderRootDir(Class forClass)
  5. getClassLoaders(ClassLoader baseClassLoader)
  6. getClassLocation(Class clazz)
  7. getClassLocation(String className)
  8. getCustomClassloader(List entries)
  9. getFileFromClassLoader(String fileName)