2

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
anubhs
  • 566
  • 1
  • 8
  • 26

2 Answers2

1

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

Ahmed Musallam
  • 9,523
  • 4
  • 27
  • 47
0

These imports are based on the code you compiled against. There are not some nasty little tidbits that are there to pester you. Their purpose is to verify that what you run against is compatible with what you compiled against. I assume that the runtime has a lower version than you require. This implies that your compile path as setup in Maven has later versions than your runtime. If you could run your code you would likely run into Class Not Found Exception or No Such Method errors.

And maybe not. But then you might have the worse situation that things are not correct (promises made during compilation might not be fulfilled) and problems might happen much later after damage has been done.

This stuff is there for a very good reason. They are like earth pin on plugs, they protect you.

How to fix this? Take a look at your dependencies. Your must ensure you compile against a version that is lower or equal then what is present in your runtime. You can first look at the versions in your POM. If these versions are not there then look at the compile path Maven uses.

Replacing the numbers in the manifest is like sawing off the earth pin on a plug because otherwise it won't fit in the wall ... bad idea.

Peter Kriens
  • 15,196
  • 1
  • 37
  • 55