1

I want to allow users to write their own plugins for my application. The usage is quite simple, after the application has started it searches some file system path for jar files and loads all of them. All jars are dependant on my PluginFramework I released to customers.

Now, questions:

  1. Is it possible to add the PluginFramework version the plugin's jar Manifest file and validate it from code?
  2. If some plugins share the same class name (and package of course), can I load them in the same class loader or do I need to create a different class loader for every plugin?
  3. Can the plugin classes(which were loaded by a custom classloader) access classes loaded by the main class loader? PluginFramework classes should be shared among all plugins.
  4. Is there a way to unload all classes loaded by a specific class loader?

Thanks.

ItamarBe
  • 482
  • 1
  • 5
  • 12
  • 1
    Sounds like the work for OSGi - maybe You should read something about this first. Just not in order to develop some home-brew solution, but to stick to well known standards? You can do all of these things within the OSGi. – Konrad Szałkowski Jan 15 '17 at 16:38
  • OSGi is however a pain to work with, when often all you want is load a few extra jars from somewhere. – john16384 Jan 15 '17 at 17:24
  • @KonradSzałkowski Thanks, i will read about OSGi to see if it suites my needs – ItamarBe Jan 16 '17 at 22:29
  • @KonradSzałkowski does using OSGi require to run my application inside a container or can it be some library i just add to my classpath? – ItamarBe Jan 19 '17 at 14:27

1 Answers1

1

I wrote a small plugin system before. So I'll answer some of your questions.

  1. No idea, I suppose so.

  2. You'll need a separate classloader if the plugins use the exact same package. I didn't do this as part of the name of the jar determined the package, so they would be unique automatically (cannot put two jars with the same name in a folder)

  3. Yes, they can.

  4. Yes, if nothing refers to those classes and the classloader anymore it will get GC'd, see: Unloading classes in java?

Community
  • 1
  • 1
john16384
  • 7,800
  • 2
  • 30
  • 44