Class ClassLoaderUtil


  • public class ClassLoaderUtil
    extends java.lang.Object
    Simple ClassLoader utility.
    Author:
    Jeanfrancois Arcand
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassLoaderUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.lang.ClassLoader createClassloader​(java.io.File libDir, java.lang.ClassLoader cl)
      Deprecated.
      removal candidate, never used
      static java.net.URLClassLoader createURLClassLoader​(java.lang.String dirPath)
      Construct a URLClassLoader based on a canonical file location.
      static java.net.URLClassLoader createURLClassLoader​(java.lang.String location, java.lang.ClassLoader parent)
      Construct a URLClassLoader based on a canonical file location.
      static java.lang.Object load​(java.lang.String clazzName)
      Load a class using the current {link Thread#getContextClassLoader}
      static java.lang.Object load​(java.lang.String clazzName, java.lang.ClassLoader classLoader)
      Load a class using the provided ClassLoader
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ClassLoaderUtil

        public ClassLoaderUtil()
    • Method Detail

      • createClassloader

        @Deprecated
        public static java.lang.ClassLoader createClassloader​(java.io.File libDir,
                                                              java.lang.ClassLoader cl)
                                                       throws java.io.IOException
        Deprecated.
        removal candidate, never used
        Create a class loader that can load classes from the specified file directory. The file directory must contains .jar or .zip
        Parameters:
        libDir - Directory with jars.
        cl - the parent ClassLoader, or null if none.
        Returns:
        A URLClassLoader that can load classes from a directory that contains jar and zip files.
        Throws:
        java.io.IOException - I/O fail
      • createURLClassLoader

        public static java.net.URLClassLoader createURLClassLoader​(java.lang.String dirPath)
                                                            throws java.io.IOException
        Construct a URLClassLoader based on a canonical file location.
        Parameters:
        dirPath - a canonical path location
        Returns:
        a URLClassLoader
        Throws:
        java.io.IOException - I/O
        java.net.MalformedURLException - Invalid URL
      • createURLClassLoader

        public static java.net.URLClassLoader createURLClassLoader​(java.lang.String location,
                                                                   java.lang.ClassLoader parent)
                                                            throws java.io.IOException
        Construct a URLClassLoader based on a canonical file location.
        Parameters:
        location - a canonical path location
        parent - ClassLoader to be used as parent for returned one.
        Returns:
        a URLClassLoader
        Throws:
        java.io.IOException - I/O
        java.net.MalformedURLException - Invalid URL
      • load

        public static java.lang.Object load​(java.lang.String clazzName)
        Load a class using the current {link Thread#getContextClassLoader}
        Parameters:
        clazzName - The name of the class you want to load.
        Returns:
        an instance of clazzname
      • load

        public static java.lang.Object load​(java.lang.String clazzName,
                                            java.lang.ClassLoader classLoader)
        Load a class using the provided ClassLoader
        Parameters:
        clazzName - The name of the class you want to load.
        classLoader - A classloader to use for loading a class.
        Returns:
        an instance of clazzname