AEM: Debug OSGI bundles in IntelliJ
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.
The API's of most bundles are well documented but the implementation details are often hidden. In some cases you might want to took 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.
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.
With the commands below you will be able to find the jar (bundle.jar) which we need later on in the steps:
1 2 3 4
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:
You are now able to add debug statements inside the implementation classes as shown here for RolloutManagerImpl
If you have any questions, do not hesitate to contact me or leave a comment below.