Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write my own plugin loader in java? [closed]

How can I implement a plugin facility in my java program?

I am working with Java. My current project is something related to a general purpose electronics hardware, which have a custom command set.

Now there is a general GUI through which one can access the hardware. The hardware behaves in different ways in different environment, i.e. for different clients. Now the problem is that the GUI must be capable of adding plugins. Plugin means, it must be capable of giving a particular facility to a customer who has the privilege. From the customer side, the addition of plugin is to be simple, like just click on a button to add a particular facility.

The reason why I think about plugins is that more and more facility will be introduced only after delivering the core product.

like image 529
Saneesh A T Avatar asked Jul 20 '26 09:07

Saneesh A T


1 Answers

You need to provide following things:

  • create an API which your plug-ins can use to change/extend the behavior of your program (IMHO this is the trickiest part)
  • define a common entry to the plug-ins, e.g., a plug-in-specific properties file defining the entry point or extension points of your plug-in (class name of a plug-in class implementing an interface)
  • dynamically load the plug-ins from a location of your choice, e.g., all *.jar files from a specific directory (take a look at URLClassLoader)

API suggestions:

  • prefer interfaces over (abstract) classes
  • it might be useful to help the user to quickly see which interfaces she could implement (e.g. IAction, notice the leading I) and which are provided by your application for plug-in usage (e.g. WindowManager)
like image 76
Mot Avatar answered Jul 21 '26 21:07

Mot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!