简体   繁体   中英

In which order does java classloader load classes?

I have two libraries of different versions in classpath. Which version will classloader load? How could I change it?

If you have

lib-v1.jar:lib-v2.jar

then it's in order. lib-v1.jar will be loaded first (analogous to PATH ).

I'd likely avoid this in practise (beyond uses for testing etc.) It can get confusing if you reference a library class in lib-v2.jar that's not in lib-v1.jar (possible if API's are retired). That way you'd load the initial class from v2, and further common classes from v1, and these may not be compatible.

这取决于将这些库列表提供给JVM的顺序。

Classloader has no information about your jar version. Generally You should avoid this kind of situations. You should hold the most recent version in your classpath

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM