Alex
Alex

Reputation: 2382

Java or Scala plugin framework

I am developing a framework where jars can be dropped into a folder and scanned for a function that can be called later. My first implementation used naive ClassLoader method where the jars were loaded and the class instance created. This is plugin architecture. The problem I ran into is the versioning. Let's say for example my host app is using third-party lib that depends on org.joda time version 1.6 and the plugin is dependent on version 2.1 of the same (newer ) library. I tried to use the Java Simple Plugin Framework but it does not seem to load my plug-ins using custom class loaders (which is what i assume i will need to overcome the version conflict and have the 2.1 version actually loaded). My next step is to try osgi. So, the question is: is this the right approach or is there a simple way that i don't know, I am coming from .net world and don't know java too well but i remember dll hell, and this seems to be the java version of it. I am developing in Scala btw, but that should not matter to the main question.

Upvotes: 3

Views: 1273

Answers (2)

OOPMan
OOPMan

Reputation: 508

Try ScalaScriptEngine. It allows you to dynamically load and compile classes from source files and supports quite a few advanced features.

Upvotes: 3

kevinpeterson
kevinpeterson

Reputation: 1172

I had a similar use-case. I wanted a simple plugin framework much like you have described, but was not ready to jump into OSGi. I went the custom classloader route, but ran into much the same problems as you have. I did try a Parent-Last Classloader, which did help with some of the jar conflicts. That might be something to look into. I looked fairly seriously into what the CI Server Jenkins had done for their plugin system - and found this article interesting.

In the end, I needed to be able to track when services are coming and going, have a service registry, etc... and realized that I was re-inventing OSGi. I switched over to pure OSGi, and even though there is a learning curve and it can be a pain sometimes, I'm glad I did.

Upvotes: 3

Related Questions