[FIXED] What loads the Java system classloader?

Issue

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?

Solution

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.

Answered By – casablanca

Answer Checked By – Laura B. (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published