简体   繁体   中英

How to prevent loading class from jar

I am writing Plugin for some Application. Lets suppose that Application hava library dependency of libA-1.0 and my plugin has similar dependency of libA-2.0. There are different in versions and are not compatible each other (ie they have different api method signatures).

How to prevent my Plugin from loading classes from libA-1.0 (or how to force it to use classes from libA.2.0)?

Is there any way to do this not writing custom classloader and not using forName, loadClassDefinition calls?

The similar problem occurs when you put some libraries to *.war archive and they do not load becouse web containter has "the same" libraries on classpath.

Thaks for any help.

Regards, Paweł

OSGI provides this functionality out of the box. I'm sure there are some other plugin frameworks that provide similar functionality.

There is a URLClassLoader which should be able to provide a lot of the functionality of loading classes from a different jar. You'll have to put in some effort to change the class loader of the Threads that are doing the work. Don't have an example on hand, would have to write one if you need a concrete example (unless you can find one with a search engine)

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