哪个jar会加载到JVM中?(Which of the jar will be loaded in the JVM?)

系统教程 行业动态 更新时间:2024-06-14 17:04:02
哪个jar会加载到JVM中?(Which of the jar will be loaded in the JVM?)

所以假设我在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 ClassLoaderBootstrap类 ( rt.jar和jre/lib其他几个重要jar文件)组成。 Extension ClassLoaderExtension类 (扩展文件夹jre/lib/ext中的jar文件)组成。 System ClassLoaderUser类 (定义在类路径中的类)组成。

因为你的类没有在#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

更多推荐

本文发布于:2023-04-24 20:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/ab1fd3cd469d7d5e2006a309548855c0.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   jar   loaded   JVM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!