How JVM works when two same jar be included in classpath

前端 未结 4 526
难免孤独
难免孤独 2021-01-01 20:27

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.jar The proble

4条回答
  •  耶瑟儿~
    2021-01-01 21:03

    If there are duplicates, it reads the one which appears first in your classpath.

    Edit A classpath file in general looks something like this..

    
            
            
        
    
    

    If your classpath looks something like above, then your JVM will look into test.jar first, as it appears first in the classpath. If you want to test it on your own, try moving the classpathentry for testnew.jar above the entry of test.jar. You will see that it now refers testnew.jar instead of test.jar.

    Reference: FindingClasses

提交回复
热议问题