Thanks for your response. I received 3 JAR files, commons-lang.jar, commons-code.jar and oauth-core.jar to include as part of OSGi bundle. So, I included all these 3 jar files. But, I observed that for commons-lang and commons-code it is using the ones available with CQ5 setup. So, I also tried to have only one jar file, oauth-core.jar, in the bundle. But, I still get errors. Given below are the steps I am using to create a bundle that embeds 3rd party (external) jar files.
step 1: Bundle creation
Step 2: Bnd file verification
Step 3: Add external JAR file to libs folder
Step 4: Build the bundle and verify in system/console/bundles/. Build doesn't have error but it still shows error as follows:
Can you please let me know what could have gone wrong?
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.
Thanks for your response.
If I understand this correctly, I need to first resolve "org.apache.http.*" related problems. This would then automatically resolve "net.oauth.*" related problem.
In order to resolve, "org.apache.http.*" related problem, I downloaded Apache HTTP Client 4.2 OSGi bundle from http://mirror.symnds.com/software/Apache//httpcomponents/httpcore/binary/httpcomponents-co re-4.2-osgi-bin.zip and installed it on my CQ instance. This now shows the packages list as shown below:
Now, if I try to create a bundle adding external jar oauth-core.jar file, it still shows errors as follows:
Any idea what could have gone wrong?
Regarding usage of 'Export-Package: *', What I am trying to do is - I have a requirement to integrate my CQ based application with a third party. The third party gives me 4 jar files and I have to make use of functions present in those jar files. As per my understanding, in order to be able to use those external jar files, I need to create OSGi bundles using the jar files. I used the steps I shared in my earlier post to create an OSGi bundle using jar file. Since, I do not know, which function I might have to use as part of integration, I am trying to include everything that is part of jar files into OSGi bundle. Let me know if my approach for this task is wrong. I hope this would help to understand my task.
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.
Here is my bnd file with all directives:
Bundle-Name: External Jar OSGI
Bundle-Description: This OSGI bundle contains external jar file
And here is what is shown in systems/console/bundle:
Imported Packagesjavax.crypto from org.apache.felix.framework (0)
javax.crypto.spec from org.apache.felix.framework (0)
javax.servlet from cqse-httpservice (21)
javax.servlet.http from cqse-httpservice (21)
net.oauth -- Cannot be resolved
net.oauth.client -- Cannot be resolved
net.oauth.client.httpclient3 -- Cannot be resolved
net.oauth.client.httpclient4 -- Cannot be resolved
net.oauth.server -- Cannot be resolved
net.oauth.signature -- Cannot be resolved
org.apache.commons.codec.binary from org.apache.commons.codec (46)
org.apache.commons.httpclient from com.day.commons.osgi.wrapper.commons-httpclient (77)
org.apache.commons.httpclient.methods from com.day.commons.osgi.wrapper.commons-httpclient (77)
org.apache.http -- Cannot be resolved
org.apache.http.client -- Cannot be resolved
org.apache.http.client.methods -- Cannot be resolved
org.apache.http.entity -- Cannot be resolved
org.apache.http.impl.client -- Cannot be resolved
org.apache.http.params -- Cannot be resolved
org.apache.http.util -- Cannot be resolved
org.osgi.framework from org.apache.felix.framework (0)
org.slf4j from slf4j.api (11)
Regarding Export-Package, I know the function, class and its package I need to use. Would it be fine if I just export that package instead of using '*'? In such case, if this has dependency on some function in one of the 4 jar files I need to use, how does it get resolved? Do I need to Export those packages as well?
Please find below Import-Package directive information:
Import-Package: com, com.gsfn, com.self.learning.osgi.oauth, javax.crypto, javax.crypto.spec, javax.servlet, javax.servlet.http, net.oauth, net.oauth.client, net.oauth.client.httpclient3, net.oauth.client.httpclient4, net.oauth.server, net.oauth.signature, org.apache.commons.codec.binary, org.apache.commons.httpclient, org.apache.commons.httpclient.methods, org.apache.commons.lang, org.apache.http, org.apache.http.client, org.apache.http.client.methods, org.apache.http.entity, org.apache.http.impl.client, org.apache.http.params, org.apache.http.util, org.osgi.framework, org.slf4j
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).
Please ignore previous one. I was making changes with additional jar files. Here is the import directive which is related to the screenshots I posted earlier:
Import-Package: com.self.learning.osgi.oauth, javax.crypto, javax.crypto.spec, javax.servlet, javax.servlet.http, net.oauth, net.oauth.client, net.oauth.client.httpclient3, net.oauth.client.httpclient4, net.oauth.server, net.oauth.signature, org.apache.commons.codec.binary, org.apache.commons.httpclient, org.apache.commons.httpclient.methods, org.apache.http, org.apache.http.client, org.apache.http.client.methods, org.apache.http.entity, org.apache.http.impl.client, org.apache.http.params, org.apache.http.util, org.osgi.framework, org.slf4j