在Java中动态加载模块 [英] Dynamic loading of modules in Java

查看:117
本文介绍了在Java中动态加载模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,我可以将动态添加到类路径和加载类(动态的意思,而不重新启动我的应用程序)。有没有一个已知的框架/库来处理动态加载/卸载模块而不重新启动?



通常的设置,特别是对于Web应用程序,是负载平衡器,几个实例的应用,并逐步部署和重新启动新版本。我正在寻找别的东西 - 应用程序与几个服务/插件,可能是单实例桌面应用程序,其中禁用单一服务是便宜的,但是关闭或重新启动完整的应用程序是不可行的。



我正在考虑典型的插件基础设施,可以在不重新启动应用程序的情况下升级或安装插件。我必须从头开始编程,还是已经可以使用的? Spring兼容和开源是一个加号,但不是一个要求。

解决方案

您可能会考虑在 OSGI框架



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



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



< hr>

注意:当你关于插件可以在不重新启动应用程序的情况下进行升级或安装的高峰, 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).

这篇关于在Java中动态加载模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆