设计一个基于插件的java应用程序
我正在尝试制作一个基于插件的应用程序,这意味着除了基本框架之外,还应该使用插件样式添加其他功能。
我认为这种系统的主要问题是如何在运行时加载新插件。我不想在安装新插件时重新编译整个项目。就像Eclipse一样,新安装插件后,用户只需重新启动插件即可。 所以我的第一个想法是使用 java 反射在运行时加载类。可能有一些插件配置文件,系统读取它们并通过反射加载插件类。也许我也可以使用spring框架,因为它的控制反转正好符合我的要求。
我正在研究的另一个想法是使用 ejb 容器。当插件是ejb时,我可以将它们打包到jar中并将它们部署到ejb容器中,然后我可以使用jndi来访问它们。但只有当插件是 ejb 时它才有效。
无论如何,我是系统设计的菜鸟。所以我发布这个主题并想听听您的意见。 顺便提一句。有什么关于系统设计的好书想推荐吗?
非常感谢!
I'm trying to make a plugin-based application which means, besides the basic framework, other functionalities should be added with a plugin style.
The majar problem of such system, i think, is how to load new plugins at the runtime. I don't want to recomplie the whole project when a new plugin installed. Just like Eclipse, after new installation of plugin, the user only need to restart it.
So my first idea about that is using java reflection to load the class at the runtime. there might be some plugin configuration files, the system reads them and load the plugin classes with reflection. Maybe i can use the spring framework as well, because its Inversion of Control is just match my request.
Another idea i'm investigating is using the ejb container. when the plugins are ejbs, i can just pack them into jar and deploy them in an ejb container, then i can use jndi to access them. but it only works when the plugin are ejbs.
anyway, i'm a rookie in system design. so i post this topic and want to hear of your opinions.
btw. is there any good book about system design you want to recommand?
thanks alot in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以首先查看 OSGI 及其实现(Equinox for Eclipse 和 Apache Felix),但如果您向我们提供有关您正在尝试执行的操作的更多信息,则会更容易。
You may first look at OSGI and his implementation (Equinox for Eclipse and Apache Felix) but it would be easier if you give us more information of what you are trying to do.
插件解决什么问题?
框架设计者通常拥有深厚的领域知识,可以指导他们的设计选择。框架是在尝试解决某个问题两三次之后产生的;早期的实现提供了有关如何将重要内容抽象到框架中的线索。
Eclipse 解决了可扩展 IDE 的问题(在我看来,效果很差)。 EJB 是在容器中运行的事务性分布式组件。
您没有表明您想要解决什么样的问题。除非你这样做,否则你的想法不会走得太远。
Plug-in to solve what problem?
Designers of frameworks usually have deep domain knowledge that informs their design choices. Frameworks come about after two or three attempts to solve some problem; the earlier implementations give clues about how to abstract what's important into a framework.
Eclipse solves the problem of an expandable IDE (poorly, in my opinion). EJBs are transactional, distributed components that run in a container.
You've given no indication of what kind of problem you want to solve. Until you do, your ideas won't get very far.