- setting up an OSGi project skeleton for development,
- adding libraries to OSGi project's internal build path,
- building OSGi projejct,
- deploying the compiled OSGi bundle in to CQ5 container.
What OSGi Bundle Can Bring to CQ
For example, if you want to write a custom library in Java that your JSP can import and use from any JSP file, you can develop an OSGi bundle. Or, if you want to some code to be triggered and executed whenever you 'activate/publish' a page node, you can develop an custom Workflow OSGi bundle with code of jobs to be executed whenever such an 'activate/publish' event is fired.
Create OSGi Bundle with CRXDE Lite
step #1: Create an OSGi bundle project skeleton
- Symbolic Name: will be used toward the final OSGi bundle jar's name.
- Name: is the name for displaying purposes in the CQ's Web console interface.
- Package: is the full Java package name of the bundle you'd create. CQ will create corresponding folder to hold the java code.
To demonstrate, I created a folder named libs, under which I put a dom4j jar and it will be picked up by CRXDE Lite's default bundle build step. Also, for demonstration purposes, I created some more Java classes (PageActivationEventHandler.java and PostpageActivationWorkflow.java) as if I had developed them and put them under the proper folder just to show where your custom Java source should go.
step #2: Modify bnd file
It is the auto-generated com.test.service.bnd file that I modified to overwrite the default to export all package and import all package:
Export-Package: * # 1
Bundle-Name: Test Bundle
step #3: Build bundle
Install OSGi Bundle Built by CRXDE Lite
To verify the bundle jar is installed, you can always go to CQ's Web Console (probably at http://localhost:4502/system/console/configMgr), and look under OSGi, Bundles to see if the bundle name specified in step #1 above shows up.
Re-install OSGi Bundle Build by CRXDE Lite
1. Delete the old OSGi bundle (.jar) file under install folder. Click 'Save' to persist the deletion. This deletion will remove the bundle from appearing in the OSGi console. In other words, delete the .jar will uninstall the bundle.
2. Modify your OSGi code with enhancement or bug fixes. Rebuild (refer to step #3 as mentioned before) it, which will re-generate bundle file (.jar) under install folder.
3. Go to OSGi Console, locate the Bundle, click on it to bring up a page that only shows that bundle, click on "Refresh Packages."