OSGi Troubleshooting

  1. Features
    1. If you depend on other apps, features, or bundles, make sure those are called out explicitly. This will save you a lot of pain troubleshooting missing dependencies later on.
  2. Bundles
    1. If your bundle fails to start, read your manifestbundle:list | grep -i <your bundle name>, then headers <bundle number>. Any unresolved imports will be highlighted in red.
    2. Bundle imports must be satisfied by bundle exports somewhere in the container. If you are wiring bundles together, double-check this on both ends. You can also exports | grep -i <package> to verify.
      1. The maven-bundle-plugin is not perfect. Sometimes you will need to exclude an undesired transitive dependency, or explicitly import an additional package. You should always be explicit with your exports.
    3. If you have dependencies that are satisfied by a jar rather than a bundle, you will need to embed those dependencies. Verify you are embedding everything you need.
    4. If you are still missing something, make sure all your prereqs are started. You may be missing something in your features file if that is the case.
  3. Blueprint
    1. Beans
      1. When instantiating beans, you must use the fully qualified class name.
      2. If you get a 'cannot cast' error, check your types.
      3. Bean args do not care about names, only ctor order and type.
      4. Bean properties expect a corresponding setter, e.g. if your property is named foobar, blueprint will look for a matching setFoobar in your class.
    2. Services
      1. When exporting services, it's best to explicitly declare interfaces.
      2. When binding to someone else's service, make sure the providing bundle is active, verify the service is being exported with services | grep -i <service>, and double-check the interface of your service ref.
  4. Metatype
    1. When a bundle comes up, beans will always be populated with any blueprint defaults before they get updated with their metatype properties.
    2. Check the pid of your metatype and managed-properties.
    3. Metatype and blueprint property names must match.
  5. Classloader
    1. Every bundle gets its own classloader. This means you can't freely share static classes between bundles like you could in a standard java application. Bundles should only communicate using services, which requires an interface for each one.
    2. Watch out for split packages. If two different bundles have two different packages with the same name and you try to wire them together, this may fail with an IllegalAccessError.