为什么 <JAVA_HOME>/jre/lib 目录中的 jar 文件没有被 bootstrap class 加载程序加载

Why jar file inside <JAVA_HOME>/jre/lib directory not loaded by bootstrap class loader

据说

The bootstrap class loader loads the core Java libraries located in the <JAVA_HOME>/jre/lib directory.

The extensions class loader loads the code in the extensions directories <JAVA_HOME>/jre/lib/ext,or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.

现在如果我的主程序是

public class TestSt {

    public static void main(String[] args) {

        System.out.println(String.class.getClassLoader());
        System.out.println(Student.class.getClassLoader());
        System.out.println(TestSt.class.getClassLoader());
    }

}

输出为

null
sun.misc.Launcher$AppClassLoader@73d16e93 sun.misc.Launcher$AppClassLoader@73d16e93

这很好。

现在,如果我将 Student Jar 文件放入 /jre/lib/ext,输出为

null
sun.misc.Launcher$ExtClassLoader@3d4eac69 sun.misc.Launcher$AppClassLoader@2a139a55

也可以。

但是我无法理解如果我把学生jar文件放在
/jre/lib 目录。为什么输出为

null
sun.misc.Launcher$AppClassLoader@73d16e93 sun.misc.Launcher$AppClassLoader@73d16e93

我在想这种情况下的 Student Class 应该从 bootstrap class 加载程序加载,为什么它是由应用程序 class 加载程序加载的。我想我错过了什么。请让我知道我哪里错了。

只有几个目录会自动加载所有 JAR。在诸如 /jre/lib 之类的目录中,仅加载它期望加载的 JAR。任何其他 JAR 都需要通过类路径加载。