Java Utililty Methods Class Loader

List of utility methods to do Class Loader

Description

The list of methods to do Class Loader are organized into topic(s).

Method

ClassloadClass(final File classFolder, final String className)
load Class
final ClassLoader cl = new URLClassLoader(new URL[] { classFolder.toURI().toURL() });
return Class.forName(className, false, cl);
ClassloadClass(String className)
load Class
try {
    if (!USE_SEPARATE_CLASSLOADER) {
        return Class.forName(className);
    String classPathValue = System.getProperty("java.class.path");
    String[] classPath = classPathValue.split(File.pathSeparator);
    URL[] classPathUrl = new URL[classPath.length];
    for (int i = 0; i < classPathUrl.length; i++) {
...
ClassloadClass(String className)
load Class
try {
    return (Class<T>) Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (ClassNotFoundException e) {
    URL[] cp = tryToGetContextClassPath();
    throw new IllegalArgumentException("Cannot load class [" + className + "] from classpath "
            + (cp == null ? "<unknown>" : Arrays.deepToString(cp)), e);
ClassloadClass(String dir, String classname)
load Class
try {
    URL[] urls = new URL[] { new URL("file:" + dir + "/") };
    ClassLoader loader = URLClassLoader.newInstance(urls);
    return loader.loadClass(classname);
} catch (Exception e) {
    e.printStackTrace();
return null;
...
ClassloadClass(String name)
load Class
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
    return Class.forName(name);
} else {
    return loader.loadClass(name);
ClassloadClass(String name, Object fallbackClass)
load Class
ClassLoader loader = getCurrentLoader(fallbackClass);
return Class.forName(name, false, loader);
Set>loadClasses(Collection filenames, String packageName, File outputDir)
load Classes
Set<Class<?>> classes = new HashSet<Class<?>>();
List<String> fullclassname = new ArrayList<String>();
for (String filename : filenames) {
    fullclassname.add(packageName + "." + filename);
try {
    URLClassLoader cl = new URLClassLoader(new URL[] { outputDir.toURI().toURL() },
            Thread.currentThread().getContextClassLoader());
...
Set>loadClassesImplementsTheInterface(String packageName, Class interfaceClazz)
load Classes Implements The Interface
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
assert classLoader != null;
String path = packageName.replace(".", "/");
Enumeration<URL> resources = classLoader.getResources(path);
List<File> dirs = new ArrayList<>();
while (resources.hasMoreElements()) {
    URL resource = resources.nextElement();
    dirs.add(new File(resource.getFile()));
...
MaploadClassifiers(String dataDirectoryName)
load Classifiers
Map<String, String[]> classifiers = new HashMap<>();
URL dir_url = ClassLoader.getSystemResource(dataDirectoryName);
File dir = new File(dir_url.toURI());
for (String dirName : dir.list()) {
    File file = new File(
            ClassLoader.getSystemResource(dataDirectoryName + File.separator + dirName).toURI());
    if (file.isDirectory()) {
        classifiers.put(file.getName(), file.list());
...
InputStreamloadConfig(String path, ClassLoader classLoader)
Opens input stream to the specified path, which can be a class resources resolved using the provided class loader, a url or a file
InputStream input = null;
URL resource = classLoader.getResource(path);
if (resource != null) {
    try {
        input = resource.openStream();
    } catch (IOException exception) {
if (input == null) {
    try {
        input = new URL(path).openStream();
    } catch (IOException exception) {
if (input == null) {
    try {
        input = new FileInputStream(path);
    } catch (IOException exception) {
return input;