集册 Java实例教程 获取类加载器

获取类加载器

欢马劈雪     最近更新时间:2020-01-02 10:19:05

477
获取类加载器

/*

 * 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;
/*
NowJava.com - 时  代  Java
*/

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 (
展开阅读全文