Troubleshooting Missing OSGi bundles

After deployment sometimes post upgrade or change in dependencies we see there are some inactive bundles in OSGi console. In this blog we will discuss how we can find out where the issue is and how we can resolve it.

Error that we get while checking inside the bundle in console at http://<aem-host>:<aem-port>/system/console/bundles/<bundle-id>.


*INFO* [OsgiInstallerImpl] org.apache.sling.installer.core.impl.tasks.BundleStartTask Could not start bundle com.acme.samples.aem.bundledependency.samples-bundle-dependency-bundle [457]. Reason: {}. Will retry.

org.osgi.framework.BundleException: Unresolved constraint in bundle com.acme.samples.aem.bundledependency.samples-bundle-dependency-bundle [457]: Unable to resolve 457.14: missing requirement [457.14] osgi.wiring.package; (&(osgi.wiring.package=org.apache.commons.beanutils)(version>=1.9.0)(!(version>=2.0.0)))

at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4095)

This means that AEM was unable to resolve my bundle dependencies at deployment time.


Use classes exported by another bundle

By default, AEM has a lot of OSGi bundles deployed and one of them may be exporting the classes that you’ve been looking for. You just need to find out which versions are being exported and add to your project the correct version as a dependency.

Let’s say that you have a Maven-based project and you want to use Apache Commons Lang. therefore:

  • Access http://<aem-host>:<aem-port>/system/console/depfinder

  • Type org.apache.commons.lang3;

  • Click on find;

  • Copy the value provided as Maven dependency;

  • Paste it into your parent POM;

  • Paste it into your child POM, removing the tags <version> and <scope>.


Apache Felix Maven Bundle Plugin

Suppose that you have a Maven-based project and you want to use Apache Commons BeanUtils. therefore.

1. Add the dependency to your POM

  • Access https://mvnrepository.com/;

  • Type commons beanutils;

  • Click on Search;

  • Select any version that depends on commons-collections 3.2.1;

  • Copy the content of the Maven tab;

  • Paste into your parent POM, adding <scope>compile</scope>;

  • Paste it into your child POM, removing the tags <version> and <scope>;

2. Instruct the Bundle Plugin to embed the dependency

  • Open your child POM;

  • Locate maven-bundle-plugin <instructions> tag;

  • Insert the following into it:

<!-- embed all compile and runtime scope dependencies -->

<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>


Example of maven file:


<build>

<plugins>

<plugin>

<groupId>org.apache.sling</groupId>

<artifactId>maven-sling-plugin</artifactId>

</plugin>

<plugin>

<groupId>org.apache.felix</groupId>

<artifactId>maven-bundle-plugin</artifactId>

<extensions>true</extensions>

<configuration>

<instructions>

<!--Importanyversionofjavax.inject,toallowrunningonmultiple

versionsofAEM-->

<Import-Package>javax.inject;version=0.0.0,*</Import-Package>

<Sling-Model-Packages>

com.honeywell

</Sling-Model-Packages>

<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>

</instructions>

</configuration>

</plugin>

</plugins>

</build>


Issue: org.apache.felix.shell,version=[1.0,2) -- Cannot be resolved

org.apache.felix.shell,version=[1.0,2) -- Cannot be resolved mean that you are trying to use these felix packages from within AEM. However - there are no OSGi bundles in AEM that exports these packages.

You can download the bundle from maven repo and upload it into the AEM Felix console and use it.

OR you can create it as your parent pom dependency as one of module and wrap along with your project jar and use it.


To verify the availability of any package and dependencies use AEM Dependency finder.


109 views0 comments

Recent Posts

See All

GraphQL - A query language for API - Part 1

Have you recently started hearing about GraphQL and wondering what is it all about? Here is a short introduction to get you up to speed. So, lets start with What is GraphQL? In simple words, its a que

"this" in javascript

Here we will talk about this keyword in javascript and how it is different from any other javascript object. "this" is and current context object in runtime engine, but unlike any other object the pro