Quick background: I am working on developing an interface that will be implemented by myself and other developers. This interface will allow users to "plugin" new functional code into a system for new use. This new code will be called from an already running server/application. (TLDR: I need to develop the ability for plugins to be installed into my application on the fly)

All the work I have done with interfaces so far have been for internal coding purposes, not to be exposed outward. The only way I can think of to allow users to plugin new code implementing interfaces, would be for the user to somehow hook a JAR file in containing the implementing class and somehow defining its class signature for call. This seems like something that has been done before, I just have never been exposed into the coding side of it.

Is there a framework I could use to allow this plugin of new Java code during server/application runtime? I have used APIs before, but in more of the web service exposing sense where you are consuming a service and not "implementing" some core interface.

For reference I am using a Java backend, with Spring for the main application.

  • 1
    Looks like a duplicate of stackoverflow.com/questions/25449/… – Esben Skov Pedersen Mar 28 '16 at 13:50
  • @EsbenSkovPedersen that led me into a rabbit hole which eventually gave me everything I needed and then some. Thank you very much. (-admins: Duplicate, close is fine by me) – Walls Mar 28 '16 at 22:07
  • @Walls duplicates must be on the same site. Just because SO has a similar question does not mean this one is a duplicate of it. You could summarize what you found in an answer to this question and link to the SO question, since answers are a bit more permanent than comments. – user22815 Mar 30 '16 at 5:13

After looking into a related post on Stack Overflow, I found there to be a variety of different tools at my disposal to do "plugin" style development.

First, I was close with "API" but the correct solution is an "SPI" or Service Provider Interface. I found a very good post describing the difference on Stack Overflow. To summarize: API is a set of classes/interfaces/methods that you CALL and USE to achieve a goal. Compared to a SPI which is a set of classes/interfaces/methods that you EXTEND and IMPLEMENT to achieve a goal.

There are many ways I am still looking through to find the right solution for me, but it seems that using Java's ClassLoader or URLClassLoader will be the way to go. Oracle provides a great tutorial on how to implement this here.

There are many tools out there that can provide support for this such as Apache Aries and OSGi.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.