All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.jerryxia.devhelper.util.ClassUtil Maven / Gradle / Ivy

Go to download

This is a helper tool library in developing or testing java web application.

There is a newer version: 1.1.2
Show newest version
/**
 * 
 */
package com.github.jerryxia.devhelper.util;

/**
 * @author Administrator
 *
 */
public class ClassUtil {
    private static final ClassLoader defaultClassLoader = ClassUtil.class.getClassLoader();

    public static ClassLoader getClassLoader() {
        if (defaultClassLoader != null) {
            return defaultClassLoader;
        } else {
            return Thread.currentThread().getContextClassLoader();
        }
    }

    /**
     * Loads a class
     * 
     * @param className
     *            - the class to load
     * @return The loaded class
     * @throws ClassNotFoundException
     *             If the class cannot be found (duh!)
     */
    public static Class classForName(String className) throws ClassNotFoundException {
        Class clazz = null;
        try {
            clazz = getClassLoader().loadClass(className);
        } catch (Exception e) {
            // Ignore. Failsafe below.
        }
        if (clazz == null) {
            clazz = Class.forName(className);
        }
        return clazz;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy