Search code examples
osgiaemosgi-bundlemanifest.mf

How the MANIFEST file is being generated in my AEM osgi bundle?


I created one maven project with aem-project-archetype version 13. After installing the bundle to AEM, I am getting error in felix console that 3 of the imported bundles could not be resolved. I am trying to find out that from where these are being included into my manifest file which is inside the target/MANIFEST folder. so that i could modify the versions of the respective bundles.

the error i am geting in felix console, my bundle is in installed state, not active

org.apache.sling.api.resource,version=[2.10,3) -- Cannot be resolved
org.apache.sling.api.servlets,version=[2.2,3) -- Cannot be resolved
org.apache.sling.models.annotations,version=[1.4,2) -- Cannot be resolved

Solution

  • When you're developing AEM applications, the OSGI bundle (and Manifest) is typically generated via the Felix maven-bundle-plugin.

    The plugin writes your package imports based on the java packages you import in your all of your Java code. If you are importing from a maven dependency, say Sling the version for that import will be the package version from Sling.

    The issue you are having here could be one of two

    1. The package you are importing does not exists in OSGI (AEM Instance)
    2. There a mismatch between the version in your maven dependencies and the version in OSGI (AEM instance). Hence OSGI cannot resolve the version you are importing.

    2. is likely the case because sling is always bundled with AEM.

    What can you do to debug/fix?

    1. You can go to http://localhost:4502/system/console/depfinder and try your packages there to see what version is actually exported in OSGI.
    2. Check wha versions of your dependencies you have in your pom.xml and make sure the OSGI version is within the range specified by the manifest imports. You can use maven dependency tree to list all your dependencies and their versions.
    3. This specific to AEM, if you are using uber-jar make sure you are using the correct version for the correct AEM instance you're running.

    Note that in manifest imports the range [2.10,3) means it accepts all versions between 2.10.0 and 3.0.0 but NOT including 3.0.0. In my experience, Maven bundle plugin will always write the range where the min is your maven dependency package version and the max is the next major version.

    Changing the imports manually:

    This is not recommended and has very specific use cases, but you could manually tell the bundle plugin what version to add to the imports. See import-package instruction in the bundle plugin docs