Java Class Loader loadClass(String dir, String classname)

Here you can find the source of loadClass(String dir, String classname)

Description

load Class

License

Open Source License

Declaration

public static Class loadClass(String dir, String classname) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.URL;
import java.net.URLClassLoader;

public class Main {
    public static Class loadClass(String dir, String classname) {
        try {//w w w  . j ava 2s  .  c  om
            URL[] urls = new URL[] { new URL("file:" + dir + "/") };
            ClassLoader loader = URLClassLoader.newInstance(urls);

            return loader.loadClass(classname);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. loadClass(ClassLoader cl, String cName)
  2. loadClass(final File baseFolder, final String qualifiedType)
  3. loadClass(final File classFolder, final String className)
  4. loadClass(String className)
  5. loadClass(String className)
  6. loadClass(String name)
  7. loadClass(String name, Object fallbackClass)
  8. loadClasses(Collection filenames, String packageName, File outputDir)
  9. loadClassesImplementsTheInterface(String packageName, Class interfaceClazz)