public final class ClassUtil extends java.lang.Object
Constructor and Description |
---|
ClassUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getClassLoaderInfo(java.lang.Class c)
Returns classloader information about the specified class.
|
static java.lang.String |
getClassLoaderInfo(java.lang.Object obj)
Returns classloader information about the specified object
|
static java.lang.String |
getClassName()
This method can be called from either a instance or a static method.
|
static java.lang.String |
getLoadedFromPath(java.lang.Class caller)
Returns either the directory or jar file from which the specified class was loaded
|
static java.lang.String |
getMainClassName()
Returns the fully qualified name of the class that contained the main() method used to
invoke the application.
|
static java.lang.String |
getParentDir(java.lang.Class caller)
Returns the right most parent directory from which the actual class was loaded.
|
static java.net.URL |
getParentDirAsURL(java.lang.Class caller)
Returns the parent directory from which the actual class was loaded.
|
static boolean |
isSystemClass(java.lang.Class c)
Returns true is the specified class is a system/JDK class.
|
static void |
main(java.lang.String[] args) |
public ClassUtil()
public static java.lang.String getClassLoaderInfo(java.lang.Object obj)
public static java.lang.String getClassLoaderInfo(java.lang.Class c)
public static java.lang.String getClassName()
Important note: The returned class name is wherever the method is invoked from. For instance methods, it is the runtime virtual class. For static it is the class name where the method was declared (static methods are not virtual and bound at compile time). For example:
Class A { static void foo(...) { System.out.print(ClassUtil.getClassName()); } } public class B extends A { } % java B will print: A (NOT B)
public static java.lang.String getMainClassName()
public static boolean isSystemClass(java.lang.Class c)
caller
- the object or Class
Class corresponding to that objectpublic static java.lang.String getLoadedFromPath(java.lang.Class caller)
This does not work for system/bootstrap classes and will return null for system classes.
caller
- the Class
class to be looked uppublic static java.lang.String getParentDir(java.lang.Class caller)
For classes loaded from other sources (jar, etc), the return value will be null.
This also does not work for system/bootstrap classes (they are typically loaded from jars) either (those will return null also)
caller
- the Class
class to be looked uppublic static java.net.URL getParentDirAsURL(java.lang.Class caller)
For classes loaded from other sources (jar, etc), a URL will be returned. For jar URL's, the URL.getProtocol() method returns "jar", so that can be useful for further processing as needed.
caller
- the Class
class to be looked uppublic static void main(java.lang.String[] args)