views:

405

answers:

1

Hi there!

Inside my host application I tried implement a simple pushService, which shall be used to transfer an instance of a class named Vehicle to the OSGi world, by providing a set and get method. To be able to use the service I exported both the service interface and the Vehicle class to a jar file and imported that file within the bundle, which should use the service.

Everytime I tried to use the Vehicle class within my host application, which instanciates the felix framework, and the bundle, I got a linkage error. After reading the following blog entry (http://frankkieviet.blogspot.com/2009/03/javalanglinkageerror-loader-constraint.html) I understood why this error occurs. But I have no clue how to solve my problem.

Is it possible to share a class between the host application and an OSGi instance? Maybe I have to use reflection instead of import the jar file? I had a look at that library (http://code.google.com/p/transloader/) and I'm don't really sure whether this lib is able to solve my problem or not ...

BR,

Markus

+1  A: 

At one time I was using Felix to do EXACTLY what you're asking in a custom client-server application. I've since switched to Equinox (they correctly implement framework fragments which I needed for swing LAF as osgi bundles). I THINK the following will work in Felix, I KNOW it works in Equinox.

UPDATE: I started down a very similar path with my host application. I realized early that I needed to move as much code as possible into real OSGi bundles to truly take advantage of the platform. My host application sets up client/server comms and synchronizes bundles; that's it. The few classes I used to share have been moved into bundle and I haven't look back. If you design/application can support having the majority of code in bundles I would definitely go that route. Even if some redesign is required, it's worth it.

Before initializing the OSGi runtime, set this property "org.osgi.framework.system.packages" to include you packages (no wildcards) separated by semi-colons ";". You may additionally need to include the base osgi packages, "org.osgi.framework" and the base services "org.osgi.packageadmin", "org.osgi.startlevel", "org.osgi.url".

I just dug through my version control and found a snippet when I was still using Felix (the setup is almost the same for Equinox)

Map<String, String> configMap = new HashMap<String, String();

configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES,
    "your.package;other.package;org.osgi.framework");

// setup other properties

Bundle systemBundle = new Felix(configMap, null);
systemBundle.start();

// Now you can use classes from "your.package" with explicity 
// declaring them as imports in bundles
basszero
Markus
What if you only list your package not the base osgi packages? Side note: Are you working on a package to interface with a verhicle CAN system? Is there hardware? What platform?
basszero
I solved the problem by myself. I had to give the name of the package as well as a version. Now I'm able to use the classes provided by my bundle from both sides. Thank you :) For my masterthesis I'm writing an environment for testing VANET applications. Using this environment it will be possible to run a OSGi application on the simulated vehicles with the open source traffic simulator SUMO.
Markus