Expand my Community achievements bar.

SOLVED

include 3rd party dependencies within OSGI bundle

Avatar

Level 2

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.

1 Accepted Solution

Avatar

Correct answer by
Level 2

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.

View solution in original post

18 Replies

Avatar

Level 10

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. 

Avatar

Level 10

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

Avatar

Level 2

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

Avatar

Level 10

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.

Avatar

Level 2

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?

Avatar

Level 2

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

Avatar

Level 2

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

Avatar

Level 10

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

Avatar

Level 2

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

Does Adobe has a profesional customer support?

Avatar

Level 2

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

Does Adobe has a profesional customer support?

Avatar

Level 10

Actually - you can download an OSGi bunlde from the main site: 

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

Then you can deploy that to AEM: 

Once this is done - you can see that org.apache.oltu.oauth2.client resolves in AEM Dependency Finder: 

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

Avatar

Level 2

Hi smacdonald2008:

Let me tell you that I really appreciate your labor here. At least you spend time trying to help the community. My bad comments are not personals, Ok?.

I already wrapped the original library in an OSGI Bundle. If you read my post with attention you can read that I have the wrapped bundle running/active in the Apache Felix console right now. 

Also, I verified the dependency using this: http://localhost:4502/system/console/depfinder

I put that dependency in my maven pom.xml, BUT I'M STILL RECEIVING THE ORIGINAL "org.apache.oltu.oauth2.client,version=[1.0,2) -- Cannot be resolved"

I've removed all the bundles, published them again, restarted the services, my PC, everything!!.

Avatar

Level 10

You asked a question on a closed thread. I answered it to help you. 

In future - you should open a new question - not ask a question on a thread that is green.  You will get more responses. 

And the answer is correct - it points to the article that talks about How TO wrap 3rd party JAR files into OSGi bundles. 

If you need more help - we can setup connect sessions and I can show you exactly how this works. 

Avatar

Level 10

You asked a question on a closed thread. I answered it to help you. 

In future - you should open a new question - not ask a question on a thread that is green.  You will get more responses. 

And the answer is correct - it points to the article that talks about How TO wrap 3rd party JAR files into OSGi bundles. 

If you need more help - we can setup connect sessions and I can show you exactly how this works. 

Avatar

Level 2

Here you can see my wrapped bundle running.

Avatar

Level 10

Can you email me your main OSGi bundle. I would need to see it to further help you. I suspect its a version issue. I sent you an email already. 

Avatar

Level 10

Just to follow up for community reading this thread - i got bundle into an active state. 

Avatar

Correct answer by
Level 2

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.