We know that we can override the System classloader with:
java -Djava.system.class.loader=com.test.MyClassLoader xxx
Then, since com.test.MyClassLoader
itself is a class, by whom is it loaded?
How do we get the class file of this "meta" classloader?
The Java ClassLoader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. The Java run time system does not need to know about files and file systems because of classloaders. Java classes aren't loaded into memory all at once, but when required by an application.
A Java Class is stored in the form of byte code in a . class file after it is compiled. The ClassLoader loads the class of the Java program into memory when it is required. The ClassLoader is hierarchical and so if there is a request to load a class, it is delegated to the parent class loader.
5. Which class loader loads jar files from JDK directory? Explanation: Extension loads jar files from lib/ext directory of the JRE. This gives the basic functionality available.
The system class loader loads code found on java. class. path , which maps to the CLASSPATH environment variable.
Bootstrap classloader
is the parent of all classloaders
and loads the standard JDK classes in lib directory of JRE (rt.jar and i18n.jar). All the java.* classes are loaded by this classloader
.
Extensions Classloader
is the immediate child of Bootstrap classloader. This classloader loads the classes in lib\ext directory of the JRE.
System-Classpath classloader
is the immediate child of Extensions classloader. It loads the classes and jars specified by the CLASSPATH
environment variable
You could try to inject your custom class loader by means of the "java.system.class.loader" property (see ClassLoader#getSystemClassLoader).
Default System class loader
is parent for MyClassLoader instances,
From the Javadoc for ClassLoader.getSystemClassLoader
:
If the system property "java.system.class.loader" is defined when this method is first invoked then the value of that property is taken to be the name of a class that will be returned as the system class loader. The class is loaded using the default system class loader and must define a public constructor that takes a single parameter of type ClassLoader which is used as the delegation parent.
The default system class loader itself is specific to the JVM implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With