I have a class which runs an Equinox framework. Now I would like to get an Object (defined in one of the bundles) that is returned by a service out of the framework.
Unfortunately, I get a LinkageError and have no idea how to get rid of it. Is it even possible to let a service return a proper object to non-bundle code?
Here is the full story:
ParserDTOBundle is a bundle that defines the class ParserDTO and exports the corresponding package.
In another bundle, ParserServiceBundle, I define a service called ParserService. This bundle imports the package of the ParserDTO. The function getDTO() of ParserService creates a new ParserDTO object and returns it.
Now I created another class which starts an Equinox framework and loads both bundles from a directory:
...
EclipseStarter.setInitialProperties(frameworkPropertiesMap);
bundleContext = EclipseStarter.startup(new String[] { "-console", "-dev", "bin" }, null);
bundleContext.installBundle("file:/" + dir + "ParserDTOBundle-0.0.1-SNAPSHOT.jar");
Bundle service = bundleContext.installBundle("file:/" + dir + "ParserServiceBundle-0.0.1-SNAPSHOT.jar");
service.start();
ServiceReference serviceReference = bundleContext.getServiceReference(ParserService.class.getName());
if (serviceReference != null) {
ParserService ps = (ParserService) bundleContext.getService(serviceReference);
if (ps != null) {
ParserDTO dto = ps.getDTO();
System.out.println(dto.getValue());
}
}
The above described class is part of a non-bundle Maven project. The run of the above class fails with:
Exception in thread "main" java.lang.LinkageError: loader constraint violation: loader (instance of sun/misc/Launcher$AppClassLoader) previously initiated loading for a different type with name "de/ParserDTO"
Interestingly, I get this error at the System.out.println and not the line before. The class loader of the ParserDTO class in my main class is obviously different from the class loader of the object dto.
How can I get the information stored in dto?? Is that even possible?? Do I have to 1.) hand my normal class loader to the bundle or 2.) use basic datatypes instead or 3.) some completly other way??
Thank you all in advance! Sebastian