I would like to develop a java web app (eg: spring-mvc) with a left menu containing "groups", each group as a set of links available to open whatever functionality represents.
I would like each "group" to be independetly deployable with a jar approach, so it would be something like:
- I put a new jar in the plugins folder
- The web app automatically detects the plugin
- A new group is automatically shown at the left menu
- Clicking any link of the new group calls the controller included in the new jar and elements are displayed at the center div of the app
My question is: Is there already any framework to manage the plugin detection / registration ?
I've read that OSGi could be a solution to approach this architecture, but I am not sure if this is the right choice for what I need.
I don't know any specific frameworks that support your requirements but I can think of two approaches how you can implement it on your own or integrate it in existing web frameworks.
OSGI:
The Apache Felix FileInstall module can automatically install and start OSGi bundles that are dropped into monitored directories. In theory, with the right server and http support modules, you can drop in your webapp bundle jar files and the OSGi container will deploy them and route all requests to the paths specified in the webapps web.xml file to your plugin.
In practice you have to learn a lot about OSGi beforehand and possible experiment a lot with different implementations of the OSGi specifications. OSGi sounds good for the features you want and certainly can do the job well, but it might be overkill if your project is small.
SPI:
If you want to go for something (much) simpler, take a look at the SPI (Service Provider Interface) API. You need to implement most features by hand with SPI though. There is no plugin lifecycle like in OSGi, but that's ok if you only want to deploy and don't plan to undeploy. You need to implement dynamic loading of jars yourself, for example like described in this question.
I don't know about Spring MVC, but you should actually be able to integrate this approach any web framework that supports dynamic addition of pages after the framework has been started. The main application would need to register all installed webapp services in the web framework and add them in the menu group. The webapps could load the site layout, menu, assets etc. from the main application and add their own content and functionality, preferably using some DI framework for all of this.