AEM: Debug OSGI bundles in IntelliJ

Jeroen Druwé
WeAreIDA
Published in
3 min readAug 9, 2021

The OSGi specification describes a modular system and a service platform for the Java programming language that implements a complete and dynamic component model, something that does not exist in standalone Java/VM environments. Applications or components, coming in the form of bundles for deployment, can be remotely installed, started, stopped, updated, and uninstalled without requiring a reboot; management of Java packages/classes is specified in great detail. Application life cycle management is implemented via APIs that allow for remote downloading of management policies. The service registry allows bundles to detect the addition of new services, or the removal of services, and adapt accordingly.

- https://en.wikipedia.org/wiki/OSGi

The API’s of most bundles are well documented but the implementation details are often hidden. In some cases you might want to take a look inside them to find out what is actually happening, IntelliJ makes this process very easy. In our example we’ll be looking at the Day Communique 5 WCM Multi Site Management Corecom.day.cq.wcm.cq-msm-core bundle.

msm bundle detail

In order to debug the code within the bundle, you will need the ID, in this case, it’s 347. You can find a list of all bundles at YOUR_AEM_INSTANCE_HERE/system/console/bundles. Inside you AEM installation folder navigate to /crx-quickstart/launchpad/felix, here you will see all bundles appended with the ID of the bundle.

felix bundles

With the commands below you will be able to find the jar (bundle.jar) which we need later on in the steps:

cd bundle347
cd version0.1
ls
bundle.jar revision.location

The steps to add the bundle.jar as a module dependency within IntelliJ are actually very well documented by Jetbrains, I’ll just share the link: https://www.jetbrains.com/help/idea/working-with-module-dependencies.html. After you completed the steps, you should see the jar in your project:

Jar added as external library in IntelliJ

You are now able to add debug statements inside the implementation classes as shown here for RolloutManagerImpl

debugging a class in IntelliJ

If you have any questions, do not hesitate to contact us or leave a comment below.

--

--