Wednesday, March 26, 2008

JAXB vs OSGI

A side note to those poor souls who have to get JAXB running with OSGI:
It works, but it is ugly.
A little story about the problem:
We have a ton of classes implementing different interfaces.
After putting a lot of work into refactoring the first release of designer I had created a ton of new interfaces.
We came to the point where we wanted to save all those nice classes with all the nice interfaces they implement to an XML file.
Since JDK 1.6 update 4 JAXB 2 is included in the JDK and we figured it might be good to give it another shot.
To make it short: as soon as one of our properties had an interface as its type the saving failed.
We followed the instructions on this site but JAXB kept telling us that it is unable to handle interfaces.
After some fiddling in a sandbox and reading through some osgi stuff I finally found out what to do:
Add the following JVM parameters and you are good:

-Dosgi.compatibility.bootdelegation=true -Dorg.osgi.framework.bootdelegation=*

It's a little brute force to do it this way and you will have a small performance impact on your app but at least it works.