如果将两个不同版本的jar文件放在classpath中会发生什么情况? [英] what happens if we put two different versions of jar files in classpath?

查看:80
本文介绍了如果将两个不同版本的jar文件放在classpath中会发生什么情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将两个不同版本的jar文件放在类路径中,会发生什么情况?
例如: log4j1.4.jar and log4j1.5.jar保留在类路径中
会发生什么?

If i put two different versions of jar files in class path, what willl happen?
for example: log4j1.4.jar and log4j1.5.jar kept in classpath
what will happen?

推荐答案

虽然我也建议不要这样做,但我仍然想尝试回答您的原始问题:

While I also recommend not to do this, I still like to try to answer your original question:

Java具有类加载器层次结构,因此,如果两个JAR都处于层次结构的不同级别,则类加载器将定义其优先级.最受欢迎的示例是Web应用程序类加载器层次结构(例如Tomcat),其中应用程序类的优先级高于容器类的优先级(如果两者均适用).

Java has a classloader hierarchy, so if you have both JARs in different levels of the hierarchy, the classloader defines its precendence. Most popular example is the web application classloader hierarchy (Tomcat for example), where application classes have a higher priority than the comtainer classes (if both are applicable).

如果两个JAR都在同一个类加载器(相同级别)中,则文件系统将确定顺序,从开发人员的角度来看这是不可靠的,因此应将其视为随机的.仅加载一个,但是您不知道加载哪个,甚至可能不会从依赖关系问题中得到错误.如果遇到依赖关系问题,则可能是java.lang.Errors,例如VerifyError,NoClassDefFoundError,NoSuchMethodError.

If you have both JARs in the same classloader (same level), the filesystem determines the order, which is unreliable from the developer's point-of-view, so consider it to be random. Only one loads, but you don't know which, and will maybe not even get errors from dependency problems. If you get dependency problems, they may be java.lang.Errors, such as VerifyError, NoClassDefFoundError, NoSuchMethodError.

这篇关于如果将两个不同版本的jar文件放在classpath中会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆