A 3rd party jar is one which is not present as a bundle in AEM OSgI. If you want to use API’s from a 3rd party jar in AEM then it needs to be added to AEM OSGI. 

If you try to upload a 3rd party jar in osgi then it won’t, get uploaded. To upload it in osgi it needs to be osgi specific with MANIFEST.MF file. OSGI bundle is nothing but jar with MANIFEST.mf file.

Lets take the example of apollo client which is NOT available in aem osgi. Apolloclient can be used to make graphql requests using graphql query.

If you are using Apolloclient API for sending graphql requests in backend. Then you probably already included the dependencies in POM to resolve the API’s. If you do a maven build it will build successfully and deploy to AEM. However, if you check in OSGI the core bundle will NOT be in active state. If you dig deeper the apolloclient dependencies are not resolved in the bundle. Reason for this is apolloclient is not available in AEM runtime.

Solution:

All jars required for the apollo client to work in aem osgi, should be embedded in core bundle and available in its classpath. All transitive dependencies of apolloclient need to be added as well. This way we are adding all the jars to bundle classpath and these jars wont be available as separate bundles in osgi.

Add all jars to include-resource of bnd maven plugin in pom. All these jars need to be added to classpath of the plugin.

Implementation: Using include-resource in bnd-maven-plugin 

We want 3rd party Apollo client jar to be available on AEM. Apollo client main jar is the apollo-client-runtime jar which is dependent on multiple transitive dependencies/jars. Add the dependencies in pom.xml to use the API’s at compile time.

core/pom.xml

All jars(including transitive dependencies) required by apollo client should be added to “-include-resource” and also to -classpath to use the API’s at runtime. 

The bundle should resolve successfully now and become active on deployment.

Jars being deployed to osgi can be seen on extracting the core bundle jar.