I looked at IPOJO from Apache Felix and managed to create a simple application with it. I think I'll start with plain OSGI programming first. Once I get it right, it will be easier to know what IPOJO or other tools can do for me and when it's better not to use them.
For example to build a simple GUI with plugins support using OSGI, the only thing I need to do if I understand, is :
- Create few services, one can think about them as extension points
- Create BundleActivators for each plugin
- Register couple of services and use some ServiceTrackers
- Layout and display your GUI application when all the bundles are activated
- Launch background services if their startup needed to be delayed
In XPontus XML Editor I have about 18 plugins which could become bundles. I started cleaning up some code. One shall never hurry too much to release, patch code here and there, leave too many unused packages, because the pain comes soon enough when you need to do some refractorings... .
In XPontus, I have 1 master project and about 30 sub-projects. Well it can be difficult to manage too, but I don't have to create many ant targets/tasks to build specific jars.
Project structure overview
- xpontus_core
- etc.
- indentation_plugin(dummy maven pom project)
-> html_indentation_plugin (sub-project, maven jar project)
The annoyance with a plugin architecture is about the deployment, but mostly the packaging. Most of the time the plugin framework or OSGI framework you'll find has a console or a main class from where you can launch the bundles/plugins. Usually in a big application, you want total control and a customized behaviour which means a custom launcher to embed the plugin framework or the OSGI framework.
Let's say I have a bundle called bundle0. I created it in Eclipse, I have few jars as dependencies, etc. How do you auto-package all that with minimal effort(zip file with the bundle0.jar, a lib directory holding the dependencies)?
In XPontus XML Editor the plugins have an "Eclipse like" folder structure
- com.mycompany.plugin
* plugin.xml
* lib(folder containing the jars)
Every time I want to deploy a plugin:
- I create a plugin folder with a unique id
- I add the plugin descriptor
- Create a lib folder with all the jars needed by the plugin
- I zip the folder and it could be ready to be deployed.
No comments:
Post a Comment