所以假设我在ext文件夹中有一个不同版本的jar,另一个版本在classpath 。 罐装哪个版本? 根据我的研究,由于extension classloader在classpath之前运行,因此将加载扩展中的库。 或者它将覆盖classpath 。 如果版本相同会发生什么?
So suppose I have a jar with a different version in the ext folder and the other version is in the classpath. Which version the the jar will be loaded? As per my research, since the extension classloader runs before the classpath one so the library in the extension will be loaded. Or will it be overriding with the classpath one. And what will happen if the version are the same?
最满意答案
它将使用它可以在ClassLoader的层次结构中找到的第一个类。
因此它将尝试从下一个ClassLoader序列中获取ClassLoader :
Bootstrap ClassLoader由Bootstrap类 ( rt.jar和jre/lib其他几个重要jar文件)组成。 Extension ClassLoader由Extension类 (扩展文件夹jre/lib/ext中的jar文件)组成。 System ClassLoader由User类 (定义在类路径中的类)组成。因为你的类没有在#1中定义,而是在#2和#3中定义,它可以找到的第一个类将在#2中,所以它将获得扩展文件夹的版本,并且只是忽略你后面定义的那个类路径。
另请参见如何找到类
It will use the first class that it can find in the ClassLoader's hierarchy.
So it will try to get the class from the next sequence of ClassLoaders:
The Bootstrap ClassLoader composed of the Bootstrap classes (the rt.jar and several other important jar files in jre/lib). The Extension ClassLoader composed of the Extension classes (jar files in the extension folder jre/lib/ext). The System ClassLoader composed of the User classes (the classes located in the classpath defined).So as your class is not defined in #1 but in #2 and #3, the first class that it can find will be in #2, so it will get the version of the extension folder and simply ignore the one defined later in your classpath.
See also How Classes are Found
更多推荐
发布评论