Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list of all classloaders in a JVM

Tags:

Is it possible to get a list of all class loaders in a JVM or at least all class loaders associated with web apps in a Java EE Server (WebLogic in my case).

like image 454
maneesh Avatar asked Jun 22 '09 11:06

maneesh


People also ask

How many JVM ClassLoaders are there?

When the JVM is started, three class loaders are used: Bootstrap class loader. Extensions class loader. System class loader.

How do I get all classes in a classpath?

You can get all classpath roots by passing an empty String into ClassLoader#getResources() . Enumeration<URL> roots = classLoader. getResources("");

How do you find the ClassLoader?

To know the ClassLoader that loads a class the getClassLoader() method is used. All classes are loaded based on their names and if any of these classes are not found then it returns a NoClassDefFoundError or ClassNotFoundException.

Is ClassLoader part of JVM?

Class loaders are responsible for loading Java classes dynamically to the JVM (Java Virtual Machine) during runtime. They're also part of the JRE (Java Runtime Environment). Therefore, the JVM doesn't need to know about the underlying files or file systems in order to run Java programs thanks to class loaders.


1 Answers

There are good overviews on the class loader hierarchy at:

Archived version of http://e-docs.bea.com/wls/docs81/programming/classloading.html

http://weblogic.sys-con.com/node/42876

You can use

ClassLoader.getParent()

to walk through you current application's applications resolution tree, but you really can't look through the children app's class loaders.

like image 178
stevedbrown Avatar answered Oct 13 '22 01:10

stevedbrown