Search code examples
javapluginsjarclassloaderdependency-management

How to isolate an API's dependencies from the main program where it is used?


I have a system for which I am creating a plugin through a well defined access point. However the plugin in question uses some jar that the framework also uses but of a different version.

The code is structured in a way where the code integrating in the framework (extending the plugin extension points) and the code doing the actual work is very well decoupled (basically boils down to an API of less than 10 classes). However behind these few classes is hidden a fairly big and complex system (60+ jar dependency)

The question is as follows :

How do I ensure that anything instantiated by the API classes is done using a seperate private library of jar files ?

In other words, how to I isolate the plugin so that it runs with it's own private library without interfering with the main application's libraries ?

---- EDIT ---- Thus far the only two ways this could be accomplish is by embedding a framework such as OSGi or by providing my own implementation of a class loader. The latter can be done and many variants are proposed on the net though I found nothing that would give me the confidence of stability I need for the system at hand.

Which returns us to OSGi, I was hoping for a more lightweight solution though perhaps once I learn the technology it will prove to do just what I want without too much effort.


Solution

  • That's what OSGi is for. And Equinox a small nice implementation.