2
votes

1) Problem 1:
I have come across this scenario quite a few times, finding transitive dependencies converting them to OSGi format and deploying them in OSGi container is already a pain.

But sometimes even after doing the above, the bundle does not start WHY ?

I double checked the imports, all are satisfied, there are no red marks, but the bundle refuses to go "Active" it always shows "Installed". Why does this happen?

2) Problem 2
Another issue I face is NoClassDefError occurring at runtime even when the class is present in Bundle and the bundle is Active.

An example for this is org.apache.xmlbeans.XmlObject NoClassDefError

If it is missing then it should show it in "red" as missing dependency, but instead it shows all dependencies resolved and bundle is Active? I extracted the contents of the bundle as well to see if it is really there, and found out that it exists then why do these weird errors occur?

Note: My working environment is Adobe CQ5.

enter image description here enter image description here

2
I have problem 1 from time to time as well, but don't have an approved solution for it. Propblem 2 could be that the the class either exposed by another bundle but in a different version or isn't exposed at all. Some packages have to be made public adding them to the sling.properties org.osgi.framework.bootdelegation - Thomas
@Thomas Regarding Problem 2, the dependencies were being resolved by some other bundle. I deleted that bundle so my bundle explicitly should missing dependencies( in red) then I added the correct supporting bundle with the class present inside it in OSGi and the dependencies were resolved but the status is still always "Installed" - Oliver
If equinox is the OSGi container below, it is very good at hiding exceptions :). Check the configuration folder as log files are created there and often exceptions are shown only in those log files. For your second question, check the source how that class would be loaded (whith which classloader). Probably Thread Contenxt Classloader is used that should not be used in OSGi. - Balazs Zsoldos
@BalazsZsoldos The container is Apache Felix standard OSGi container. How do I check which class loader is being used? I have access to log files - Oliver
@Oliver: When you get the NoClassDefFoundError, check the stack trace. The place where the class would have been loaded, will be hopefully somewhere on the top. It would be useful if you could share the stack trace in the issue. There can be two possibilities. Class is simply used in another class (linked) or it is used via reflection. In the first case, it is an issue with the bundle wires, in the second case, the code is not really OSGi friendly. - Balazs Zsoldos

2 Answers

3
votes
  1. Simply start the bundle by hand from the shell (I hope CQ has a shell). It should show an exception that helps you.
  2. NoClassDefFound can happen if a bundle accesses a class but does not define an Import-Package statement for the package. If the class is even inside the same bundle then NoClassDefFound means that the bundle does not use the standard classloader. So maybe the bundle is not well prepared for OSGi. You should report such errors as an issue at the community that creates the bundle.
2
votes

A likely cause for bundles not starting is their activators throwing exceptions. Those should be visible in the logs, and if not I would set a breakpoint in the bundle Activator to see what's happening.