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?
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
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.
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?
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.
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
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