17

Please give an advise on how to do "plugin" architecture for Java web application.

Currently we are using quite simple and standard Spring+Hibernate+Struts 2 in Tomcat servlet container. (Built with maven)

I need something like Redmine. Where any module can be enabled/disabled, updated Redmine UI

Please exclude heavy options like OSGi, Portlet.

  • OSGi is too heavy, there is no good adoption of the technology for web. I already looked at Eclipse Germini;
  • Portlet it just old, and never was popular.
Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
Paul Verest
  • 60,022
  • 51
  • 208
  • 332

3 Answers3

16

I will try to provide several possible solution. I did spent some time preparing small PoCs for the project I'm working on, so let's hope the options below are relevant.

Important note: it is really easy to define some extension point, do resolve and find available implementations. There are a lot of solutions available, for example good and simple one -- JSPF

Resources are the main problem for WEB applications

OSGi

OSGi, is not that bad and can be useful. It seems to be heavy (and some implementations are heavy) but this is price of standardized platform. I would suggest to check Apache Felix. It can be used in a "lightweight" mode. By the way, it includes Web Console which is build as loosely coupled plugin-based application, could be helpful:

enter image description here

Some examples Extending the Apache Felix Web Console

The Web Console can be extended by registering an OSGi service for the interface javax.servlet.Servlet with the service property felix.webconsole.label set to the label (last segment in the URL) of the page. The respective service is called a Web Console Plugin or a plugin for short.

You can also check eie-manager which is clean and simple and uses OSGi to manage plugins. Could be a good example for you.

Custom plugin framework

I would suggest to review solution behind Jenkins/Hudson. I would say Jenkins plug-in system is quite mature and reliable. Can be used as a good example.

enter image description here

Please also check Hudson Plugin Architecture

Simple solution

For my project I've build plugin abstraction layer based on JSPF with custom dependency resolver.

PROS:

  • simple and small
  • clean concept
  • works good

CONS:

  • without proper plugin management can be slow (full classpath search)
  • provides very basic functionality
  • may require additional attention

I would suggest to use JSPF only if you really need some simplicity and want to control everything. JPF provides a lot of interesting features out of the box, for example:

Plug-ins can be "hot-registered" and even de-registered during application execution. What's more, registered plug-ins can be activated and deactivated "on the fly", minimizing runtime resource usage.

The problem is JPF is dead.

Suggestion

Do spend some time with Apache Felix. It is mature enough, so your time investments may pay back a lot.

Renat Gilmanov
  • 17,735
  • 5
  • 39
  • 56
6

Check out the answers to this question: Best way to build a Plugin system with Java

If you don't trust the plugin code, you can implement sandboxing, as described here: Sandbox against malicious code in a Java application

The open-source Java Plug-in Framework project supports plugin deactivation, you can get inspired from it even if it is too heavy for your purposes.

Community
  • 1
  • 1
lbalazscs
  • 17,474
  • 7
  • 42
  • 50
  • How to apply this to web parts? Would you make all plugins as .war? – Paul Verest Jan 18 '13 at 03:34
  • Well, if these plugins can be independent webapps, then you don't have to do anything, for example the Tomcat manager webapp allows you to start/stop/reload the webapps without having to shut down and restart the server: http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html – lbalazscs Jan 18 '13 at 10:23
  • plugins should not be independent webapps. In this way there will be a lot work of how to integrate them (cross links, security, simgle sign-on etc) – Paul Verest Jan 22 '13 at 08:44
  • Then I guess it makes no sense to make the plugins as .war files. – lbalazscs Jan 22 '13 at 10:18
2

Atlassian open sourced their plugin system here. I see it is being worked heavily by Atlassian team. Worth to explore its documentation

asyncwait
  • 4,457
  • 4
  • 40
  • 53