Java Class Loader loadClasses(Collection filenames, String packageName, File outputDir)

Here you can find the source of loadClasses(Collection filenames, String packageName, File outputDir)

Description

load Classes

License

Apache License

Declaration

private static Set<Class<?>> loadClasses(Collection<String> filenames, String packageName, File outputDir) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;

import java.util.Set;

public class Main {
    private static Set<Class<?>> loadClasses(Collection<String> filenames, String packageName, File outputDir) {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        List<String> fullclassname = new ArrayList<String>();
        for (String filename : filenames) {
            fullclassname.add(packageName + "." + filename);
        }/*from   www.  j av  a2s  . c  om*/
        try {
            URLClassLoader cl = new URLClassLoader(new URL[] { outputDir.toURI().toURL() },
                    Thread.currentThread().getContextClassLoader());
            for (String c : fullclassname) {
                classes.add(cl.loadClass(c));
            }
            Thread.currentThread().setContextClassLoader(cl);
            return classes;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. loadClass(String className)
  2. loadClass(String className)
  3. loadClass(String dir, String classname)
  4. loadClass(String name)
  5. loadClass(String name, Object fallbackClass)
  6. loadClassesImplementsTheInterface(String packageName, Class interfaceClazz)
  7. loadClassifiers(String dataDirectoryName)
  8. loadConfig(String path, ClassLoader classLoader)
  9. loadForClass(final Class clazz, final String filename)