It been two days I am playing a lot with OSGI framework and also in a process of learning the technology so stay clam if you find any mistakes.
While learning I came across a challenge to use Derby as a service in OSGI framework.
The Googling BEGINS !!!!
After searching for a while I came across that there is a plugin for derby in eclipse but I was reluctant to use eclipse plugin because I wanted to use the service on other implementation of OSGI framework without other dependences that eclipse will import in, while creating a bundle.
OK the Idea is to create a standalone derby database service which other bundles can use it.
So in a process of hunting information on web I found THE LINK for OSGI bundle repositories
Searched for derby bundle in the repository and lucky found it.
Downloaded the derby : Derby Bundle.
Now as a new learner of OSGI it was a challenge for me to use this third party service in eclipse environment.
So I created a testDerby bundle which is supposed to use the Derby bundle I have downloaded.
Oh MY Dayssss
I didn't realize that eclipse can be a pain. As far as I know eclipse don't have any options to import third party plugin residing in a directory of your own choice.
It seems that you can only use plugin in eclipse which are in the plugin directory of eclipse installation directory..
So I tried to copy the derby bundle to plugin directory of the eclipse (It may sound absurd to many eclipse gurus but hey I tired every means.)
Well still no success.
After couple of hours of banging my head in front of my laptop. An alternate way struck in my head. :P
Eclipse have a feature to create a OSGI bungle/plugin from a third party jar file.
Wait a minute!!! Isn't a derby bundle I download is a OSGI bundle already ? Yes it is..
So we gonna play with a jar and create a new OSGI bundle from eclipse
Right, created a new Project on eclipse. By following the steps mentioned below
File-> New-> Project-> Select "Plugin from an Existing Jar Archive".
Click on Add External
Select the Derby.jar you have downloaded from the osgi website I have mentioned above
Click Finish.
Volla!!!!
Eclipse have created a new Project which include a derby.jar which we have downloaded.
Right, work is not done yet.
Now Click on the MANIFEST.MF file or the newly created derby project.
Click on the MANIFEST.MF Tab of the tabpane.
And change the following Headers
Export-Package
Import-Package
To the mentioned below :
Export-Package: org.apache.derby.authentication,
org.apache.derby.database,
org.apache.derby.iapi.jdbc,
org.apache.derby.io,
org.apache.derby.jdbc,
org.apache.derby.vti
Import-Package: javax.naming.spi,
javax.naming.directory,
javax.transaction.xa,
javax.crypto,
org.osgi.framework; version="1.3.0",
javax.sql,
javax.crypto.spec,
javax.naming
Add bundle activator the bundle
Bundle-Activator: org.apache.derby.osgi.EmbeddedActivator
You don't have to write an EmbeddedActivator class , it is already in the derby bundle we have downloaded.
Right almost done...
Now we have to export the project as plugin with the help of eclipse.
So in the package Explorer pane Right click on derby project and click on Export
In Export window
Click on Deployable plug-ins and fragments option
Click Next-> select the "derby"
Browse the Directory you want to export the plugin
Go to the directory which you selected and Volla!!!
You got a brand new derby bundle which will work with equinox and Apache felix and also a eclipse project which can be used to create/test bundle requiring Derby functionality .
Now you can create you test bundle to test the derby database baby.
So the Zest of post is that now we can create other bundles requiring Derby functionality with the help of the derby project we have just created. And also now we don't have to use the eclipse derby bundle which comes with other dependencies.
Hope the post made sense to you guys/gals
And also if you know any other ways to use third party bundle in eclipse please do help me out as well
Thanks
0 comments:
Post a Comment