Posts Tagged ‘ibm’

Felix and Websphere 7

December 25, 2010

Recently I have ran into issues running Apache’s Felix Project in IBM Websphere 7. When you try and start an embedded Felix OSGi container you get class cast exceptions that classes are not properly matching the interfaces. Specifically I saw that the bundles implementations don’t match BundleActivator interface. Also you could see issues with the “getBundleContext” method not existing on the Bundle class. After some gnashing of teeth I have found the fix for this and its took a little digging so hopefully this will save folks time with the same issue.

The problem…

Websphere 7 (and possibly 6.1+) is including on the classpath org.osgi.core packages which include versions of the interfaces used included in the Felix jars. Also the classes get loaded into the bootstrap classloader which is prefered by Felix when when loading classes. The net result is if you have class loading set to parent first (the default setting) you will see missing methods on interfaces being called, specifically Bundle.getBundleContext. If you have parent last classloading set you will still see issues and all your bundles will not be able to initialize because of class casting issues on BundleActivator (or maybe other interfaces as well). The casting issues are from classes being loaded from different classloaders, bootstrap verses application, when that happens classes even if they have the exact same methods on them will not properly cast to each other. I believe you’ll see most of your issues in the System Bundles for class casting.

The Solution…

There is a pretty simple two part solution which can be accomplished via no code changes…

  1. Ensure your Felix and related classes are included in your war file or some other class loader ahead of the bootstrap class loader in a ‘parent last’ setting. Generally this means set your Web Application to parent last class loading. If you are loading Felix classes from somewhere else ensure the class loader you are loading them with is a parent last classloader.
  2. Update the org.osgi.framework.bundle.parent configuration to ‘framework’. The easiest way to do this just add that exact property name as a system property with value ‘framework’. By default Felix delegates class loading to the bootstrap class loader overriding the class loading strategy set on the initializing code which is what is causing the class cast exception due to multiple versions of the classes getting loaded.

For more configuration properties available for Felix visit


XML4J to Xerces Version

September 22, 2010

I have always thought the fact that IBM packages in their websphere JRE libraries a re-packaging of several xml jars specifically Xerces and Xalan. They call it the XML4J jar (the file name will be xml.jar). You can check out the version of the XML4J which is associated with your IBM JRE by running the following

java  org.apache.xerces.impl.Version

That’s supposed to give you the Xerces version However that’s the XML4J version not the Xerces version. I was able to find on an IBM support forum ( which lists out the version mapping. I have place it below as well for folks to see as well.

XML4J Version Xerces Version
3.2.x 1.4.1 + defect fixes
4.0.x 2.0 + defect fixes
4.2.x 2.4 + defect fixes
4.3.x 2.6.2 + defect fixes
4.4.x 2.6.2 + defect fixes
4.5.x 2.8.1 + defect fixes