问题描述
这是我的同事的一个错误:有一个名为test.jar的jar,他修复了它的错误。然后他重新编译代码并构建了一个名为testnew.jar的新jar
问题是他将这两个jar放入classpath中的一个文件夹中。
因此,当程序运行时,行为是一种混乱。我不知道发生了什么,但在删除test.jar之后,everthing又恢复了。
It was a mistake of my co-worker: there was a jar named test.jar and he has fixed a bug of it. Then he re-compile the code and built a new jar named testnew.jarThe problem was he put these two jar into one folder which in classpath.So when program was running, the behavior was a kind of mess. I didn't know what had happened but after removing test.jar, everthing was fine again.
所以我想知道JVM的行为是什么。它是否在第一个jar中使用类文件?或者是其他东西?
So I'm wondering what's the behavior of JVM. Does it use the class file in first jar it meet? Or something else?
谢谢。
推荐答案
是的,默认情况下它使用来自的类第一个罐子。这就是为什么你必须检查库目录中的重复项。对我和我的同事来说,这么多次。
Yeah, by default it uses classes from first jar. That's why you have to check library directory for duplicates. Happend so many times for me and my colleagues.
这篇关于当两个相同的jar包含在类路径中时,JVM如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!