Empty OSGi bundle causes OSGi Framework refresh | AEM 6.x

Issue

When deploying code to AEM we see that the OSGi framework bundle gets refreshed causing an outage in AEM. In the logs we see messages similar to the ones below for our custom bundle: 

19.04.2017 15:09:11.606 *INFO* [OsgiInstallerImpl] org.apache.sling.audit.osgi.installer Updated bundle custom-bundle-name [496] from resource TaskResource(url=jcrinstall:/apps/customapp/install/custom-bundle-name-1.2.0-SNAPSHOT.jar, entity=bundle:custom-bundle-name, state=INSTALL, attributes=[org.apache.sling.installer.api.tasks.ResourceTransformer=:9035:9042:9011:, Bundle-SymbolicName=custom-bundle-name, Bundle-Version=1.2.0.SNAPSHOT], digest=1492632551274)
19.04.2017 15:09:11.607 *INFO* [OsgiInstallerImpl] org.apache.sling.audit.osgi.installer Refreshing 1 bundles: [custom-bundle-name [496]]
19.04.2017 15:09:11.608 *INFO* [OsgiInstallerImpl] org.apache.sling.audit.osgi.installer Waiting up to 90 seconds for bundles refresh
19.04.2017 15:09:11.609 *INFO* [OsgiInstallerImpl] org.apache.sling.audit.osgi.installer Done refreshing 1 bundles
19.04.2017 15:09:11.609 *INFO* [OsgiInstallerImpl] custom-bundle-nameBundleEvent RESOLVED
19.04.2017 15:09:11.609 *INFO* [OsgiInstallerImpl] custom-bundle-name BundleEvent STARTING
19.04.2017 15:09:11.609 *INFO* [OsgiInstallerImpl] custom-bundle-name BundleEvent STARTED
19.04.2017 15:09:11.610 *INFO* [OsgiInstallerImpl] org.apache.sling.audit.osgi.installer Started bundle custom-bundle-name [496]
19.04.2017 15:09:11.627 *INFO* [FelixDispatchQueue] org.apache.felix.framework FrameworkEvent PACKAGES REFRESHED

Environment

AEM 6.x

Cause

1. One possible cause is that the bundle has no exports or imports or any code in it. This is known to cause the issue.
2. The custom bundle could be exporting system level java packages that are already exported and used by some core AEM, Apache Felix or Sling bundle

Resolution

Empty OSGi Bundle

If you are deploying an empty bundle then stop doing so. It is not valid to do so unless it is a fragment bundle containing resources.

System Level Export

If you are exporting some library that is used by the system (AEM, Sling, Apache Felix, Oak, etc.), then modify your custom bundle to embed the library using the maven-bundle-plugin <Embed-Dependency> tag. You can choose whether or not to add the library to the <Export-Package> tag. You will still be able to access the library within the code in the bundle but it wouldn't be exported to all other bundles.

 Adobe

Get help faster and easier

New user?

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online