List of utility methods to do Class Load
Class | loadClassFromClassLoader(String fillyQualifiedClassName) load Class From Class Loader Class clazz = null; try { clazz = wsasClassLoader.loadClass(fillyQualifiedClassName); } catch (ClassNotFoundException e) { e.printStackTrace(); return clazz; |
Class | loadClassFromContextClassLoader(String theClassName) Try loading class using the Context class loader. return Class.forName(theClassName, true, Thread.currentThread().getContextClassLoader());
|
Class> | loadClassOrNull(String className) load Class Or Null ClassLoader loader = getClassLoaderForResolving(); try { return loader.loadClass(className); } catch (ClassNotFoundException e) { return null; |
Class> | loadClassOrReturnNull(ClassLoader loader, String className) load Class Or Return Null if (loader == null) { loader = ClassLoader.getSystemClassLoader(); try { return loader.loadClass(className); } catch (ClassNotFoundException e) { return null; |
Class> | loadClassReflectively(ClassLoader classLoader, String fullyQualifiedClassName) load Class Reflectively try { return classLoader.loadClass(fullyQualifiedClassName); } catch (ClassNotFoundException e) { throw new RuntimeException(e); |
Class> | loadClassSafe(final String klassName) Loads a class with given klassName. try { return Class.forName(klassName); } catch (ClassNotFoundException e) { return null; |
Class> | loadClassSilently(ClassLoader cl, String name) load Class Silently Class<?> clz; try { clz = cl.loadClass(name); return clz; } catch (ClassNotFoundException e) { return null; |
Class | loadClassUsingClass(Class clazz, String name) This is a simple utility class that attempts to load the named class using the class loader of the supplied class or the class loader of one of its super classes or their implemented interfaces. Class loadedClass = null; while (clazz != null) { ClassLoader loader = clazz.getClassLoader(); loader = (loader == null) ? ClassLoader.getSystemClassLoader() : loader; try { return loader.loadClass(name); } catch (ClassNotFoundException ex) { Class[] ifcs = clazz.getInterfaces(); for (int i = 0; i < ifcs.length; i++) { loadedClass = loadClassUsingClass(ifcs[i], name); if (loadedClass != null) { return loadedClass; clazz = clazz.getSuperclass(); return null; |
Class> | loadClassViaContext(String fqcn) load Class Via Context ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { return loader == null ? null : loader.loadClass(fqcn); } catch (ClassNotFoundException e) { return null; |
Class> | loadClassWithTCCL(String name) load Class With TCCL if ("byte[]".equals(name)) { return byte[].class; return Thread.currentThread().getContextClassLoader().loadClass(name); |