且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Java中动态加载模块

更新时间:2023-12-05 08:59:40

您可能会考虑在 OSGI框架



我相信 DMServer 是一个基于模块的Java应用服务器,旨在运行企业Java应用程序,基于 OSGI 的弹簧式应用程序



您可以在此您好, OSGi,第2部分:Spring动态模块简介文章,特别是如何使用Spring DM在正在运行的系统中动态安装,更新和卸载模块。





注意:当你关于插件可以在不重新启动应用程序的情况下进行升级或安装的高峰, OSGI 是第一个考虑到的候选框架。



所有这些都是将应用程序模块化成较小的包。

每个捆绑是一个紧密耦合的动态可加载的类,jar和配置文件,它们明确声明了它们的外部依赖关系(如果有的话)。


In Java, I can dynamically add stuff to classpath and load classes ("dynamically" meaning without restarting my application). Is there a known framework/library which deals with dynamic loading/unloading of modules without restart?

The usual setup, especially for web-apps, is load balancer, several instances of application, and gradual deployment and restart of new version. I'm looking for something else - application with several services/plugins, possibly single-instance desktop application, where disabling single service is cheap, but bringing down or restarting complete application is not feasible.

I'm thinking about typical plugin infrastructure, where plugins can be upgraded or installed without restarting application. Do I have to program that from scratch, or is something already available? Spring-compatible and opensource is a plus, but not a requirement.

You might consider running your spring application in an OSGI framework.

I believe the DMServer is a module-based Java application server that is designed to run enterprise Java applications and Spring-powered applications, based on OSGI

You can find more details in this Hello, OSGi, Part 2: Introduction to Spring Dynamic Modules article, in particular how to use Spring DM to dynamically install, update, and uninstall modules in a running system.


Note: when you speak about "plugins can be upgraded or installed without restarting application", OSGI is the first candidate framework that comes to mind.

It is all about modularization of applications into smaller bundles.
Each bundle is a tightly-coupled, dynamically loadable collection of classes, jars, and configuration files that explicitly declare their external dependencies (if any).