简体   繁体   中英

loading class from latest version of library jar with URLClassloader

I have 2 versions of jar file (plugins1.0.jar and plugins2.0,jar) in same folder and trying to load Class from these jar files dynamically using URLClassloader. I want to ensure that the class should be loaded from latest version of jar file.

How can i achieve this?

Thanks in advance

You will need to construct your list of urls in such a way that plugins2.0.jar occurs before plugins1.0.jar . But generally it's a bad idea as other classes may have conflicting versions loaded.

From Java docs

The URLs will be searched in the order specified for classes and resources after first searching in the parent class loader.

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