ClassLoader

1)  class.getClassLoader() which is the classLoader that loaded the class. Some implementations represent bootStrap loaders with null and will return null to imply bootStrap loader loaded this class.

2) Thread.curretThread().getContextClassLoader() is the context classLoader that was set when creating this Thread (for use by code running in this thread) or the context of the parent Thread. The context Class Loader of the primordial thread is typically set to the class loader used to load this application.

3) classLoader.getResources(“xxxx”)  => loads resources with the given name that can be accessed by the class code. Name of the resource is / separated path of the resource from class.

4) class.forName() runs the static initialization (initialize the class) along with class  where as classLoader.loadClass() just loads the class but doesn’t run the static initialization. class.forName() and class.getResource() use current classes class loader.

5) other class loaders System class loader, Extension class loader, Boot strap class loader etc.,

reference:

http://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader

http://stackoverflow.com/questions/8100376/class-forname-vs-classloader-loadclass-which-to-use-for-dynamic-loading

https://jira.springsource.org/browse/SPR-1670 “Not all jar files do have a META-INF directory entry even when files exists like META-INF/manifest.mf. For instance jars build with eclipse do not contain a META-INF directory entry so this approach will not find these jars.”

Leave a comment