Loader JVM class cannot load custom jar from extension class path

I am studying the loading process of the jvm class and found out the following fact:

The class loader subsystem uses the delegation hierarchy algorithm. It will search along the path from the path BootStrap → path extension → Application path.

Then I want to "try" this in real code, as shown below:

create class A and class B; Class A with main () method and type B variable.

after compilation, I used the jar command to get the jar file of class B from B.class, then delete the B.class file, put the B.jar file in jdk / jre / lib / ext (Since the oracle document says that extClassLoader will not look for which any free cool file in jdk / jre / lib / ext).

Result of ClassNotFoundException.so My question is:

1) Does jvm not allow loading custom clasfile from BootStrap and extension class paths?

2) if so, why load it using the delegation hierarchy algorithm, which seems to lead to low efficiency?

tks ....

+4
source share
2 answers

Things seem a little strange.

After a few times a ClassNotFoundException, I got a java.lang.IllegalAccessError, which at least indicates that the extclassloader is trying to access my B.jar class

since I did not declare a package for classes A and B. This could be the reason, so I just added a public modifier to my class B and did the same as above, finally ExtClassLoader works with my B.jar.

, jvm jar, ... , jvm ( BootStrap Ext class path),

0

, - .

lib/endorsed java.lang*.

JVM .

0

Source: https://habr.com/ru/post/1649734/


All Articles