include 3rd party dependencies within OSGI bundle | Community
Skip to main content
October 16, 2015
Solved

include 3rd party dependencies within OSGI bundle

  • October 16, 2015
  • 18 replies
  • 9792 views

What is the best approach to deploy 3rd party dependencies to AEM OSGI / Felix via Maven build of OSGI bundle?

My team has a requirement to build an OSGI Servlet.  It will use dependency org.apache.oltu.oauth2.client that does not exist in CQ.

I have a pom to build the servlet now and it references the 3rd party dependency.  But when I deploy to AEM OSGI, I see this:

Imported Packages.......
org.apache.oltu.oauth2.client,version=[1.0,2) -- Cannot be resolved

What is the best way / recommend approach to resolve this issue ?  I think we need to package 3rd party dependencies within the OSGI bundle for our servlet?  If yes, how do we specify this in maven POM ?

Thanks in advance for helpful replies.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by deisbel_diaz

Hi:

finally we figure out what is the real problem: the wrapped bundle generated by the Eclipse plugin

If you see the first wrapped bundle you can note that despite the bundle number is correctly registered as 1.0.1 all its Exported Packages are registered with version=0.0.0. Looks like the real dependencies resolver in AEM uses these version numbers instead of the general bundle's version number. 

So, the solution is to edit the manifest of the library to be wrapped and exported to assign the correct version number to each Exported Package. 

After that your are able to export it correctly, and install it manually in AEM/Apache Felix console. 

Hereinafter your main bundle will be installed without problems of dependencies.

18 replies

smacdonald2008
October 16, 2015

Also check to see if that does exist - but you are referencing the wrong version.

You can use AEM dependency finder to see if this package is already part of AEM:

http://localhost:4502/system/console/depfinder

October 16, 2015

thank you smacdonald for the quick and helpful replies.

"you are referencing the wrong version"

what is the right version then ?

dependency finder just shows this below - no version info is listed.  how do I know what version to specify in pom to use the version already in AEM?

       
org.apache.oltu.oauth2-No exporting bundle(s) foundNo maven information available
smacdonald2008
October 16, 2015

that means there is no version at all. Refer to my first thread. Read the article and bundle up your dependency in an OSGi bundle that contains the JAR you are missing. You need a JAR that exposes org.apache.oltu.oauth2.client.

smacdonald2008
October 16, 2015

You are correct - you are missing this JAR file in AEM service container. 

Referencing the Maven dependency is just 1 step. You have to bundle up the JAR file into an OSGi bundle and deploy to AEM via the felix console and place that bundle into an Active state. 

We have a community article that shows you how to do this. An AEM Servlet has a dependency on the JSON simple JAR. This artilce will teach you how to bundle up a 3rd party JAR and deploy along with the main OSGi bundle. 

See: 

https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

Notice this section:

Add the org.json.simple.JSONObject data type to Adobe CQ 

Add the org.json.simple.JSONObject class to Adobe CQ. The reason is because the doPost method in the Sling Servlet uses this class to encode form data to JSON formatted data. If you do not add this class to Adobe CQ, then you are unable to place the OSGi bundle that contains the Sling Servlet into an Active state.

....

Hope this helps. 

deisbel_diaz
April 7, 2016

I had the same problem. 

I followed all the steps in https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html and I have the imported bundle running in the console. 

But, my main bundle is not Starting yet, caused by the same error: "org.apache.oltu.oauth2.client,version=[1.0,2) -- Cannot be resolved"

How I have to update the maven references? 

<dependency>
                <groupId>org.apache.oltu.oauth2</groupId>
                <artifactId>org.apache.oltu.oauth2.client</artifactId>
                <version>1.0.1</version>
                <scope>provided</scope>
            </dependency>

The above is what I'm keeping in my bundle dependencies. 

I tried to remove this dependency and add the imported oauth2 bundle as external reference to my main bundle project. Doing that, I'm able to compile and deploy my main bundle, start it, but the services are not running.

No errors exists in error.log!!

Any idea?

deisbel_diaz
April 7, 2016

HI:

I'm just doinf the same, at the same time, ha ha. There you go my imported bundle (rename to org.apache.oltu.oauth2.client_1.0.1.jar). There are 30 steps to follow to get that ready to use, so you can avoid to follow them. 

After that you can see if you have the same problem as me. 

Thanks

deisbel_diaz
April 7, 2016

HI:

I'm just doinf the same, at the same time, ha ha. There you go my imported bundle (rename to org.apache.oltu.oauth2.client_1.0.1.jar). There are 30 steps to follow to get that ready to use, so you can avoid to follow them. 

After that you can see if you have the same problem as me. 

Thanks

smacdonald2008
April 7, 2016

You are missing this package from AEM service container. org.apache.oltu.oauth2.client. 

You need to wrap a JAR that contains this Java package  into an OSGi bundle. YOu can get that JAR here: 

http://mvnrepository.com/artifact/org.apache.oltu.oauth2/org.apache.oltu.oauth2.client/1.0.1

deisbel_diaz
April 7, 2016

How can you mark as resolved a post when it is not solved?

Does Adobe has a profesional customer support?

deisbel_diaz
April 7, 2016

How can you mark as resolved a post when it is not solved?

Does Adobe has a profesional customer support?