I have some jar file which is not osgi bundle. Let's call it starter.jar. And I run this starter this way: java -jar starter.jar. This starter starts felix framework:
Felix felix = new Felix(configMap);
systemBundle=felix.getBundle();
and after that installs and starts osgi bundles which export some services.
So starter is outside osgi container, however it has reference to systemBundle. Is it possible and normal (safe) to use some osgi services in starter.jar?
EDIT Now I know that this is possible, because I have working solution (the code from starter.jar):
BundleContext bundleContext=systemBundle.getBundleContext();
ServiceReference reference = bundleContext.getServiceReference(Temp.class.getName());
Object server = (Object) bundleContext.getService(reference);
Method method = server.getClass().getMethod("getString");
Object result=method.invoke(server);
I had to use reflection as I got classCastExceptions because of different classloaders. And final solution is rather ugly. Maybe someone will offer a better way. Or there is no way except via network socket?