CQ-OPS

Adobe Experience Manager (AEM) Operations
Blog by Jayan Kandathil that specializes in Adobe Experience Manager (CQ, now AEM) ops such as deployment architecture, server sizing, infrastructure, operations, cloud, performance etc.
  • April 26, 2012 11:13 pm

    How to Turn a JDBC Driver JAR into an OSGi Bundle JAR for Apache Felix

    What makes a regular POJO .jar (Java ARchive) file an OSGi bundle (also a .jar file) is some additional MANIFEST.MF headers required by the OSGi specification.  These are required for the JAR to be deployed to Adobe CQ’s OSGi runtime framework which is Apache Felix.

    DOWNLOAD THE JDBC DRIVER JAR
    ———————————————————-

    1) Download the JDBC driver JAR file (Eg: ojdbc6.jar, the Oracle 11g R2 JDBC driver for Java 6 and 7).  This could also be MySQL Connector/J, or Microsoft JDBC Driver for SQL Server.

    CREATE AN ECLIPSE PLUGIN PROJECT
    ——————————————————————-

    2) Start Eclipse (Indigo).  The steps below have been tested on “Eclipse Java EE IDE for Web Developers" version "Indigo Service Release 1”.

    3) File->New->Other

    4) Under the “Plug-in Development” folder, choose “Plug-in from Existing JAR Archives

    5) In the “JAR selection” dialog, click the ‘Add external’ button, and browse to the JDBC JAR file you just downloaded

    6) Click Next

    7) In the “Plug-in Project properties” dialog, ensure that you check the checkbox for “Analyze library contents and add dependencies” (see below)

    8) Make sure that the “Target Platform” is the “standard" OSGi framework (see below)

    9) Ensure the checkboxes for “Unzip the JAR archives into the project” and “Update references to the JAR files” are both checked (see below)

    10) Click Next, and then ‘Finish’

    11) Click on the ‘Runtime’ tab

    12) Make sure that the ‘Exported Packages’ list is populated

    13) Make sure these have been added under the Export-Package header in MANIFEST.MF

    14) Also make sure that the Import-Package header in MANIFEST.MF is also populated.  See sample MANIFEST.MF here.

    14) Save the project

    BUILD THE BUNDLE
    ——————————-

    15) Right mouse-click the project in the left pane, choose Export->Plug-in Development->Deployable plug-ins and fragments and click Next.

    16) Choose a location for the export (C:\TEMP) and click ‘Finish’

    17) Ignore any error messages

    18) In C:\TEMP\plugins, you should now find the OSGi bundle named com.oracle.jdbc_11.2.0.3.jar

    DEPLOY BUNDLE TO APACHE FELIX
    ————————————————————

    19) Login to CQ’s Apache Felix Web Console at http://server:port/system/console/bundles (default admin user = admin with password= admin)

    20) Sort the bundle list by “Id” and note the Id of the last bundle (Eg.

    21) Click the “Install/Update” button

    22) Check the “Start Bundle” checkbox

    23) Browse to the bundle JAR file you just built (C:\TEMP\plugins\com.oracle.jdbc_11.2.0.3.jar)

    24) Click “Install or Update”

    25) Click the ‘Refresh Packages’ button

    26) Check the bundle with the highest Id

    27) Your new bundle should now be listed with the status ‘Active’

    If the status is not “Active”, check the CQ error.log for exceptions.  If you get “org.osgi.framework.BundleException: Unresolved constraint” errors, check the MANIFEST.MF for strict version requirements which might look as follows:

    org.objectweb.asm; version=”3.1.0”

    If the version requirement is bogus, remove it so that the entry looks like this:

    org.objectweb.asm,

    If the entry is not required, remove it entirely.

    28) Rebuild the bundle

    29) Delete the previous bundle and deploy the new one

    If all goes well, the CQ error.log should have log entries such as follows:

    *INFO* [FelixDispatchQueue] com.oracle.jdbc BundleEvent INSTALLED
    *INFO* [FelixDispatchQueue] com.oracle.jdbc BundleEvent RESOLVED
    *INFO* [FelixDispatchQueue] com.oracle.jdbc BundleEvent STARTED
    *INFO* [FelixDispatchQueue] org.apache.felix.framework FrameworkEvent PACKAGES REFRESHED

    Also, see this.

    1. cq-ops posted this