简体   繁体   English

Java Web应用程序“插件”架构

[英]Java Web application “plugin” architecture

Please give an advise on how to do "plugin" architecture for Java web application. 请提供有关如何为Java Web应用程序执行“插件”体系结构的建议。

Currently we are using quite simple and standard Spring+Hibernate+Struts 2 in Tomcat servlet container. 目前我们在Tomcat servlet容器中使用了非常简单和标准的Spring + Hibernate + Struts 2。 (Built with maven) (用maven建造)

I need something like Redmine . 我需要像Redmine这样的东西。 Where any module can be enabled/disabled, updated 可以启用/禁用任何模块,更新 Redmine UI

Please exclude heavy options like OSGi, Portlet. 请排除OSGi,Portlet等重要选项。

  • OSGi is too heavy, there is no good adoption of the technology for web. OSGi太重了,没有很好地采用网络技术。 I already looked at Eclipse Germini ; 我已经看过Eclipse Germini ;
  • Portlet it just old, and never was popular. Portlet它只是旧的,从未受欢迎。

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. 我确实花了一些时间为我正在进行的项目准备小型PoC,所以我们希望下面的选项是相关的。

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 有很多可用的解决方案,例如好的和简单的解决方案 - JSPF

Resources are the main problem for WEB applications 资源是WEB应用程序的主要问题

OSGi OSGi的

OSGi, is not that bad and can be useful. OSGi,并不是那么糟糕,可能很有用。 It seems to be heavy (and some implementations are heavy) but this is price of standardized platform. 它似乎很重(有些实现很重)但这是标准化平台的价格。 I would suggest to check Apache Felix . 我建议检查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: 顺便说一句,它包括构建为松散耦合的基于插件的应用程序的Web控制台,可能会有所帮助:

在此输入图像描述

Some examples Extending the Apache Felix Web Console 一些示例扩展Apache Felix Web控制台

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. 可以通过为接口javax.servlet.Servlet注册OSGi服务来扩展Web控制台,并将服务属性felix.webconsole.label设置为页面的标签(URL中的最后一个段)。 The respective service is called a Web Console Plugin or a plugin for short. 相应的服务称为Web控制台插件或简称插件。

You can also check eie-manager which is clean and simple and uses OSGi to manage plugins. 您还可以查看eie-manager ,它简洁明了,并使用OSGi来管理插件。 Could be a good example for you. 可能是一个很好的例子。

Custom plugin framework 自定义插件框架

I would suggest to review solution behind Jenkins/Hudson . 我建议审查Jenkins / Hudson背后的解决方案。 I would say Jenkins plug-in system is quite mature and reliable. 我会说Jenkins插件系统非常成熟可靠。 Can be used as a good example. 可以作为一个很好的例子。

在此输入图像描述

Please also check Hudson Plugin Architecture 还请检查Hudson插件架构

Simple solution 简单解决方案

For my project I've build plugin abstraction layer based on JSPF with custom dependency resolver. 对于我的项目,我使用自定义依赖项解析器构建了基于JSPF的插件抽象层。

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. 我建议只使用JSPF,如果你真的需要一些简单性并想控制一切。 JPF provides a lot of interesting features out of the box, for example: JPF提供了许多开箱即用的有趣功能,例如:

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. 问题是JPF已经死了。

Suggestion 建议

Do spend some time with Apache Felix . 花点时间在Apache Felix上 It is mature enough, so your time investments may pay back a lot. 它足够成熟,所以你的时间投资可能会收回很多。

Check out the answers to this question: Best way to build a Plugin system with Java 看看这个问题的答案: 用Java构建插件系统的最佳方法

If you don't trust the plugin code, you can implement sandboxing, as described here: Sandbox against malicious code in a Java application 如果您不信任插件代码,则可以实现沙盒,如下所述: 沙箱对抗Java应用程序中的恶意代码

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. 开源Java Plug-in Framework项目支持插件停用,即使它太重,您也可以从中受到启发。

Atlassian open sourced their plugin system here . Atlassian 在这里开源他们的插件系统。 I see it is being worked heavily by Atlassian team. 我看到Atlassian团队正在大力开展工作。 Worth to explore its documentation 值得探索其文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM