Expand my Community achievements bar.

Unable to use external jars in aem environment (OSGi)

Avatar

Level 3

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?

7 Replies

Avatar

Employee Advisor

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

Avatar

Community Advisor

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.



Arun Patidar

Avatar

Level 3

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?

Avatar

Community Advisor

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.

Avatar

Level 10

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

Avatar

Level 1

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

Avatar

Level 1

Hi @rasikawanjari

Make sure you should use only OSGi support spring versions.

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