Package jodd.util
Class ClassLoaderUtil
java.lang.Object
jodd.util.ClassLoaderUtil
Utilities to manipulate class path, define and find classes etc.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringclassLocation(Class clazz) Returns location of the class.static InputStreamgetClassAsStream(Class clazz) Opens a class of the specified name for reading using class classloader.static InputStreamgetClassAsStream(String className) Opens a class of the specified name for reading.static InputStreamgetClassAsStream(String className, ClassLoader classLoader) Opens a class of the specified name for reading using provided class loader.static StringgetClasspathItemBaseDir(File classpathItem) Returns base folder for classpath item.static ManifestgetClasspathItemManifest(File classpathItem) Returns classpath item manifest ornullif not found.static ClassLoaderReturns thread context class loader.static ClassLoaderReturns default class loader.static ClassLoaderReturns system class loader.static ClassLoads a class using default class loader strategy.static ClassloadClass(String className, ClassLoader classLoader) Loads a class using default class loader strategy.
-
Field Details
-
classLoaderStrategy
-
MANIFESTS
-
-
Constructor Details
-
ClassLoaderUtil
public ClassLoaderUtil()
-
-
Method Details
-
getDefaultClassLoader
Returns default class loader. By default, it isthreads context class loader. If this one isnull, then class loader of the caller class is returned. -
getContextClassLoader
Returns thread context class loader. -
getSystemClassLoader
Returns system class loader. -
getClasspathItemManifest
Returns classpath item manifest ornullif not found. -
getClasspathItemBaseDir
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
Opens a class of the specified name for reading using class classloader.- Throws:
IOException
-
getClassAsStream
Opens a class of the specified name for reading. No specific classloader is used for loading class.- Throws:
IOException
-
getClassAsStream
public static InputStream getClassAsStream(String className, ClassLoader classLoader) throws IOException Opens a class of the specified name for reading using provided class loader.- Throws:
IOException
-
loadClass
Loads a class using default class loader strategy.- Throws:
ClassNotFoundException- See Also:
-
loadClass
public static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException Loads a class using default class loader strategy.- Throws:
ClassNotFoundException- See Also:
-
classLocation
Returns location of the class. If class is not in a jar, it's classpath is returned; otherwise the jar location.
-