This blog will be helpful for devs who are working on some OSGI project in Java. OSGI framework is used to develop modular application and libraries. The deployable component of OSGI framework is know as “Bundle” which can be JAR or WAR. We can create separate bundle for each module of our application and we can easily add/remove this bundle without restarting the container. OSGI framework very flexible to manage dependencies between multiple bundles. There are many advantages of OSGI framework, you will get more information on their official website.
If you are working on project OSGI based project then you will definitely need some 3rd party libraries to resolve dependencies of bundles. So many times you need to create some customized bundles from existing JAR/Libraries, hence this blog will help you to create OSGI bundle from existing JAR. I have used Eclipse IDE to demonstrate, how can we create OSGI bundle from existing JAR’s.
We need to follow the steps given below:
1. Create a New Plugin project by selection File-> New -> Project…-> Plug-in Development -> “Plug-in from Existing JAR Archives”
2. Add required jar files with the help of “Add External” option.
3. Fill the necessary information which is required for Bundle’s Manifest.mf file.
4. Select an OSGI framework as “Equinox” in Target Platform frame.
5. Uncheck the flag Unzip the JAR archive into the project.
Unchecking the checkbox Unzip the JAR archive into the project, prevents extracting class files from the Jar which is usually not necessary.
6. Press then finish. This will create a new project for you in selected workspace.
7. Now Remove the Java dependency from “Execution Environment”.
8. Open Manifest.mf and check the Exported packages which you want to make available for other bundles.
9. Now we are going to export this bundle from Export Functionality of Eclipse. Select your bundle and choose File -> Export -> Plug-in Development -> “Deployable plug-ins and fragment”.
10. Select the required bundles and Destination Directory.
In this way, we can create a OSGI bundle from existing JAR with the help of Eclipse.
Hope this blog will help you to understand to create your own OSGI bundles from existing JAR.
Please don’t forget to comment your feedback for this post. 🙂