Modifier and Type | Method and Description |
---|---|
static ClassLoader |
getClassLoader()
Returns the ClassLoader to use.
|
static ClassLoader |
getClassLoader(Class<?> class1,
Class<?> class2) |
static URL |
getResource(String resource,
ClassLoader defaultLoader)
This method will search for
resource in different
places. |
static InputStream |
getResourceAsStream(String resource,
ClassLoader defaultLoader)
This method will search for
resource in different
places. |
static ClassLoader |
getThreadContextClassLoader()
Returns the ClassLoader of current thread if possible, or falls back to the system ClassLoader if none is
available.
|
static Class<?> |
initializeClass(String className,
ClassLoader loader)
Loads and initializes a named Class using a given ClassLoader.
|
static boolean |
isClassAvailable(String className)
Determines if a named Class can be loaded or not.
|
static boolean |
isJansiAvailable() |
static Class<?> |
loadClass(String className)
Loads a class by name.
|
static Class<?> |
loadClass(String className,
ClassLoader loader)
Loads a named Class using a given ClassLoader.
|
static Class<?> |
loadSystemClass(String className)
Load a Class in the
java.* namespace by name. |
static <T> T |
newCheckedInstanceOf(String className,
Class<T> clazz)
Loads, instantiates, and casts a Class using the default constructor.
|
static <T> T |
newCheckedInstanceOfProperty(String propertyName,
Class<T> clazz)
Loads and instantiates a class given by a property name.
|
static <T> T |
newInstanceOf(String className)
Loads and instantiates a Class using the default constructor.
|
public static ClassLoader getClassLoader()
public static ClassLoader getThreadContextClassLoader()
LoaderUtil.getThreadContextClassLoader()
public static ClassLoader getClassLoader(Class<?> class1, Class<?> class2)
public static URL getResource(String resource, ClassLoader defaultLoader)
resource
in different
places. The search order is as follows:
resource
using the thread context
class loader under Java2. If that fails, search for
resource
using the class loader that loaded this
class (Loader
). Under JDK 1.1, only the the class
loader that loaded this class (Loader
) is used.ClassLoader.getSystemResource(resource)
, that is is
using the system class loader in JDK 1.2 and virtual machine's
built-in class loader in JDK 1.1.resource
- The resource to load.defaultLoader
- The default ClassLoader.public static InputStream getResourceAsStream(String resource, ClassLoader defaultLoader)
resource
in different
places. The search order is as follows:
resource
using the thread context
class loader under Java2. If that fails, search for
resource
using the class loader that loaded this
class (Loader
). Under JDK 1.1, only the the class
loader that loaded this class (Loader
) is used.ClassLoader.getSystemResource(resource)
, that is is
using the system class loader in JDK 1.2 and virtual machine's
built-in class loader in JDK 1.1.resource
- The resource to load.defaultLoader
- The default ClassLoader.public static Class<?> initializeClass(String className, ClassLoader loader) throws ClassNotFoundException
className
- The class name.loader
- The class loader.ClassNotFoundException
- if the class could not be found.public static Class<?> loadClass(String className, ClassLoader loader) throws ClassNotFoundException
className
- The class name.loader
- The class loader.ClassNotFoundException
- if the class could not be found.public static Class<?> loadSystemClass(String className) throws ClassNotFoundException
java.*
namespace by name. Useful for peculiar scenarios typically involving
Google App Engine.className
- The class name.ClassNotFoundException
- if the Class could not be found.public static <T> T newInstanceOf(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException
className
- The class name.ClassNotFoundException
- if the class isn't available to the usual ClassLoadersIllegalAccessException
- if the class can't be instantiated through a public constructorInstantiationException
- if there was an exception whilst instantiating the classNoSuchMethodException
- if there isn't a no-args constructor on the classInvocationTargetException
- if there was an exception whilst constructing the classpublic static <T> T newCheckedInstanceOf(String className, Class<T> clazz) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException
T
- The type to cast it to.className
- The class name.clazz
- The class to cast it to.T
ClassNotFoundException
- if the class isn't available to the usual ClassLoadersIllegalAccessException
- if the class can't be instantiated through a public constructorInstantiationException
- if there was an exception whilst instantiating the classNoSuchMethodException
- if there isn't a no-args constructor on the classInvocationTargetException
- if there was an exception whilst constructing the classClassCastException
- if the constructed object isn't type compatible with T
public static <T> T newCheckedInstanceOfProperty(String propertyName, Class<T> clazz) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException
T
- The type to cast it to.propertyName
- The property name to look up a class name for.clazz
- The class to cast it to.null
if the property was unset.ClassNotFoundException
- if the class isn't available to the usual ClassLoadersIllegalAccessException
- if the class can't be instantiated through a public constructorInstantiationException
- if there was an exception whilst instantiating the classNoSuchMethodException
- if there isn't a no-args constructor on the classInvocationTargetException
- if there was an exception whilst constructing the classClassCastException
- if the constructed object isn't type compatible with T
public static boolean isClassAvailable(String className)
className
- The class name.true
if the class could be found or false
otherwise.public static boolean isJansiAvailable()
public static Class<?> loadClass(String className) throws ClassNotFoundException
#IGNORE_TCCL_PROPERTY
Log4j property. If this property is
specified and set to anything besides false
, then the default ClassLoader will be used.className
- The class name.ClassNotFoundException
- if the specified class name could not be foundCopyright © 1999-2021 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.