get Class Loader - Java Reflection

Java examples for Reflection:Class Loader

Description

get Class Loader

Demo Code

/*/*from   ww  w .  j  av a 2 s  .co m*/
 * Copyright (C) 2011 Saarland University
 * 
 * This file is part of Javalanche.
 * 
 * Javalanche is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Javalanche 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 Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser Public License
 * along with Javalanche.  If not, see <http://www.gnu.org/licenses/>.
 */
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;

public class Main{
    public static ClassLoader getClassLoader(ClassLoader parent) {
        String property = System.getProperty("java.class.path");
        String[] entries = property.split(":");
        List<URL> urls = new ArrayList<URL>();
        for (String entry : entries) {
            File f = new File(entry);
            try {
                urls.add(f.toURI().toURL());
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }
        ClassLoader classLoader = new MyURLClassLoader(
                urls.toArray(new URL[0]), parent);
        return classLoader;
    }
}

Related Tutorials