Skip navigation
Currently Being Moderated

OSGI bundle creation using third party jar files

May 23, 2012 2:23 PM

Hi,

 

I have a requirement to integrate our CQ5.5 based application with a third party. As part of this, I have to use some jar files. After lot of digging, I realised that the way to use external jar files is to create an OSGI bundle wrapping these jar files.

So, I tried to do the same, but when I see the service details in system/console, I see errors. Can someone please suggest what could have gone wrong?

 

I have to use 3 jar files. So, I placed them in lib folder as shown in the screenshot below.

1.png

 

Ibuilt the bundle using .bnd file. It generated a jar file in install folder and I am able to to see its details in system/console/bundles. When I try to view details of the OSGI bundle that is installed, I see errors as follows:

2.png

 
Replies
  • Justin Edelson
    276 posts
    Nov 24, 2010
    Currently Being Moderated
    May 29, 2012 2:13 PM   in reply to kmkwarrior

    When you embed JARs like this, the contents of those JARs become part of your bundle and any packages used by those JARs are, by necessity, added to the Import-Package directive.

     

    Given that CQ includes commons-lang and commons-code, I wonder why you're embedding them.

     
    |
    Mark as:
  • Justin Edelson
    276 posts
    Nov 24, 2010
    Currently Being Moderated
    May 29, 2012 2:48 PM   in reply to kmkwarrior

    Those unresolved packages are dependencies of your bundle and are not resolvable in the container. Nothing went wrong.

     
    |
    Mark as:
  • Justin Edelson
    276 posts
    Nov 24, 2010
    Currently Being Moderated
    May 29, 2012 3:49 PM   in reply to kmkwarrior

    For a bundle to start, all of its imports (unless they are optional) must be exported into the OSGi container. In this case, you have two batches of problematic imports:

    * net.oauth.* - these appear to be exported by the bundle itself, so once the other issue is resolved, this will be as well.

    * org.apache.http.* - IIRC, these are packages exported by Apache HTTP Client 4.x. This is not available by default in CQ 5.5, so you will need to obtain this bundle and install it. I belive the standard distribution of HTTP Client is an OSGi bundle, but I imagine some Googling will confirm that for you.

     

    I would, btw, not recommend using Export-Package: *. This means that the entire contents of your bundle is exported. Typically (although there are exceptions), this isn't warranted. OSGi bundles should export as little as possible. In many cases, bundles don't need to export ANYTHING because they are simply implementing service interfaces defined in other bundles and exposing those implementations via the Service Registry.

     
    |
    Mark as:
  • Justin Edelson
    276 posts
    Nov 24, 2010
    Currently Being Moderated
    May 30, 2012 12:47 PM   in reply to kmkwarrior

    It's not clear to me from the screenshots what is going wrong. Can you post the actual Import-Package directive - in plain text, not a screenshot?

     

    Regarding Export-Package, your understanding isn't necessarily accurate. Only the packages which will be used by other bundles (or, in the case of CQ, JSPs) need to be exported. Without knowing what your bundle does or how other code interact with it, I can't provide any better guidance other than to say that 9 times out of 10, when I see Export-Package: *, it's wrong.

     
    |
    Mark as:
  • Justin Edelson
    276 posts
    Nov 24, 2010
    Currently Being Moderated
    May 30, 2012 1:28 PM   in reply to kmkwarrior

    As I said, please post the actual Import-Package directive.

     

    Yes - you should only export the package you need.

     
    |
    Mark as:
  • Justin Edelson
    276 posts
    Nov 24, 2010
    Currently Being Moderated
    May 30, 2012 1:59 PM   in reply to kmkwarrior

    I think you also need another httpcomponents bundle. The client bundles don't seem to be exported by the httpcomponents bundle you did install. Sorry - I don't know much about the packaging of HttpClient 4.x. I find the 3.x API much easier to use and haven't needed to upgrade any of my code.

     

    Is it possible that this oauth JAR supports both HTTP Client 3.x and 4.x? I see both packages. If so, perhaps you don't need to import org.apache.http.* at all and can just import org.apache.commons.httpclient.* (which is exported by a CQ-provided bundle).

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points