Java Class Load classForName(String className, Class caller)

Here you can find the source of classForName(String className, Class caller)

Description

class For Name

License

Apache License

Declaration

public static Class classForName(String className, Class caller) 

Method Source Code

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

public class Main {
    public static Class classForName(String className, Class caller) {
        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        Class rtn = null;/*from   w  w  w  . jav a  2s.  c o  m*/
        try {
            rtn = Class.forName(className, true, tccl);
        } catch (ClassNotFoundException e) {
        }

        if (rtn == null) {
            ClassLoader callerClassLoader = caller.getClassLoader();
            try {
                rtn = Class.forName(className, true, callerClassLoader);
            } catch (ClassNotFoundException e) {
            }
        }

        if (rtn == null) {
            ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
            try {
                rtn = Class.forName(className, true, systemClassLoader);
            } catch (ClassNotFoundException e) {
            }
        }

        return rtn;
    }
}

Related

  1. classForName(String className)
  2. classForName(String className)
  3. classForName(String className)
  4. classForName(String className)
  5. classForName(String className)
  6. classForName(String className, Class superClass)
  7. classForName(String className, ClassLoader classLoader)
  8. classForName(String clazzName, ClassLoader classLoader)
  9. classForName(String cname)