1

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 (i.e. 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ł

pawel.panasewicz
  • 1,831
  • 16
  • 27

1 Answers1

0

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)

pimaster
  • 1,907
  • 10
  • 11
  • When and how can I change classloader. Assume that my plugin has method entryPoint() in class MyPlugin and this method is called by Application I mentioned before. When the runtime begins to execute method entryPoint() the class MyPlugin is just by some classloader. If I change the classloader in Thread.getCurrentThread().setContextClassloader() to my custom UrlClassLoader will this work? Why /Wny Not? Explanation is welcome :) – pawel.panasewicz Jul 26 '12 at 10:58