Highlighted

Unable to use external jars in aem environment (OSGi)

Avatar

Avatar

rasikawanjari

Avatar

rasikawanjari

rasikawanjari

03-04-2019

We have a third party jar which we want to use in our AEM project. We have added dependencies in pom files, it is resolving those jars only in eclipse but when it comes to Felix console it is not showing under the imported package and not giving any jars that have been added in dependencies. Hence, we are getting classnotfound exception while calling any methods from a jar.

Also, is it feasible if external project jar has the dependency on spring jar, can we include it in AEM as well?

Replies

Highlighted

Avatar

Avatar

jbrar

Employee

Avatar

jbrar

Employee

jbrar
Employee

03-04-2019

I believe you need to add that jar to the OSGI console in order to use the services associated with that jar file.

You can include any jar within AEM as long as it is able to resolve the imported/exported bundle list mentioned in the metadata of that jar file

Highlighted

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831
Arun_Patidar
MVP

03-04-2019

worth to notice if jars are not osgi bundles.

You can not use jar directly in AEM, need to converted the Jar into bundle with help of the link "https://helpx.adobe.com/experience-manager/kb/ConvertAJarIntoOsgiBundle.html" , Now your bundle is ready to be uploaded into AEM through felix console.

Highlighted

Avatar

Avatar

rasikawanjari

Avatar

rasikawanjari

rasikawanjari

04-04-2019

what to do in a scenario where the jar file has dependencies on other external jar files.I am facing this issue where i create the osgi bundle from normal jar and  upload it on AEM console but when I am trying to hit my servlet there it needs third party (spring)jars , so it giving
java.lang.NoClassDefFoundError: org/springframework/web/client/RestClientException.What can I do in this case?

Highlighted

Avatar

Avatar

Prince_Shivhare

Avatar

Prince_Shivhare

Prince_Shivhare

04-04-2019

if you have added the dependency and jar is downloaded in your m2. repo then you need to manually put the jar in system/console.

upload the jar from m2 only.

Highlighted

Avatar

Avatar

AshokPelluru

Avatar

AshokPelluru

AshokPelluru

04-04-2019

If that jar's not OSGi support, you should convert them to OSGi jars by simply adding the manifest file.

Here you go how to do that: How to Convert a jar File into an OSGi Bundle

Adobe Experience Manager (AEM/CQ5) : How to Convert a jar File into an OSGi Bundle

Highlighted

Avatar

Avatar

Gaurav-Behl

MVP

Total Posts

1.1K

Likes

226

Correct Answer

281

Avatar

Gaurav-Behl

MVP

Total Posts

1.1K

Likes

226

Correct Answer

281
Gaurav-Behl
MVP

04-04-2019

If you want to use Spring in AEM for "some use case", then use Spring DM or Blueprint or similar container. One single jar file wouldn't work, you'd need to setup entire container.

If you are getting classnotfound exception, then package the jar (non-spring jars, packaging spring bundles won't work), and update your pom.xml's "maven-bundle-plugin" accordingly

Highlighted

Avatar

Avatar

AshokPelluru

Avatar

AshokPelluru

AshokPelluru

04-04-2019

Hi @rasikawanjari

Make sure you should use only OSGi support spring versions.

Screen Shot 2019-04-04 at 4.54.14 PM.png