Package jodd.util

Class ClassLoaderUtil


  • public class ClassLoaderUtil
    extends java.lang.Object
    Utilities to manipulate class path, define and find classes etc.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassLoaderUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String classLocation​(java.lang.Class clazz)
      Returns location of the class.
      static java.io.InputStream getClassAsStream​(java.lang.Class clazz)
      Opens a class of the specified name for reading using class classloader.
      static java.io.InputStream getClassAsStream​(java.lang.String className)
      Opens a class of the specified name for reading.
      static java.io.InputStream getClassAsStream​(java.lang.String className, java.lang.ClassLoader classLoader)
      Opens a class of the specified name for reading using provided class loader.
      static java.lang.String getClasspathItemBaseDir​(java.io.File classpathItem)
      Returns base folder for classpath item.
      static java.util.jar.Manifest getClasspathItemManifest​(java.io.File classpathItem)
      Returns classpath item manifest or null if not found.
      static java.lang.ClassLoader getContextClassLoader()
      Returns thread context class loader.
      static java.lang.ClassLoader getDefaultClassLoader()
      Returns default class loader.
      static java.lang.ClassLoader getSystemClassLoader()
      Returns system class loader.
      static java.lang.Class loadClass​(java.lang.String className)
      Loads a class using default class loader strategy.
      static java.lang.Class loadClass​(java.lang.String className, java.lang.ClassLoader classLoader)
      Loads a class using default class loader strategy.
      • 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

      • getDefaultClassLoader

        public static java.lang.ClassLoader getDefaultClassLoader()
        Returns default class loader. By default, it is threads context class loader. If this one is null, then class loader of the caller class is returned.
      • getContextClassLoader

        public static java.lang.ClassLoader getContextClassLoader()
        Returns thread context class loader.
      • getSystemClassLoader

        public static java.lang.ClassLoader getSystemClassLoader()
        Returns system class loader.
      • getClasspathItemManifest

        public static java.util.jar.Manifest getClasspathItemManifest​(java.io.File classpathItem)
        Returns classpath item manifest or null if not found.
      • getClasspathItemBaseDir

        public static java.lang.String getClasspathItemBaseDir​(java.io.File classpathItem)
        Returns base folder for classpath item. If item is a (jar) file, its parent is returned. If item is a directory, its name is returned.
      • getClassAsStream

        public static java.io.InputStream getClassAsStream​(java.lang.Class clazz)
                                                    throws java.io.IOException
        Opens a class of the specified name for reading using class classloader.
        Throws:
        java.io.IOException
      • getClassAsStream

        public static java.io.InputStream getClassAsStream​(java.lang.String className)
                                                    throws java.io.IOException
        Opens a class of the specified name for reading. No specific classloader is used for loading class.
        Throws:
        java.io.IOException
      • getClassAsStream

        public static java.io.InputStream getClassAsStream​(java.lang.String className,
                                                           java.lang.ClassLoader classLoader)
                                                    throws java.io.IOException
        Opens a class of the specified name for reading using provided class loader.
        Throws:
        java.io.IOException
      • loadClass

        public static java.lang.Class loadClass​(java.lang.String className)
                                         throws java.lang.ClassNotFoundException
        Loads a class using default class loader strategy.
        Throws:
        java.lang.ClassNotFoundException
        See Also:
        ClassLoaderStrategy.DefaultClassLoaderStrategy
      • loadClass

        public static java.lang.Class loadClass​(java.lang.String className,
                                                java.lang.ClassLoader classLoader)
                                         throws java.lang.ClassNotFoundException
        Loads a class using default class loader strategy.
        Throws:
        java.lang.ClassNotFoundException
        See Also:
        ClassLoaderStrategy.DefaultClassLoaderStrategy
      • classLocation

        public static java.lang.String classLocation​(java.lang.Class clazz)
        Returns location of the class. If class is not in a jar, it's classpath is returned; otherwise the jar location.