Java Class Path getClass(String parentPath, String className)

Here you can find the source of getClass(String parentPath, String className)

Description

get Class

License

Apache License

Declaration

public static Class getClass(String parentPath, String className) throws Exception 

Method Source Code


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

import java.io.File;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;

public class Main {
    public static Class getClass(String parentPath, String className) throws Exception {
        // ClassLoader c = new ClassLoader(new URL[]{});
        File file = new File(parentPath);
        URI uri = file.toURI();//  w ww  .j av a 2  s . c  o m
        URL url = uri.toURL();
        URL[] urls = new URL[] { url };

        // Create a new class loader with the directory
        ClassLoader loader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());

        Class cls = loader.loadClass(className);
        return cls;
    }
}

Related

  1. getAbsolutePath(Class theClass, String path)
  2. getAbsolutePath(final Class clazz, final String relative)
  3. getApplicationPath(Class cls)
  4. getAppPath(Class clazz)
  5. getClassAbsolutePath(Class c)
  6. getClassBasePath(Class aClass)
  7. getClassFilePath(Class clazz)
  8. getClassFilePath(Class clazz)