0

I am trying to get Frame work factory to load OSGi bundles in my maven project. I have tried the following :

import org.osgi.framework.launch.FrameworkFactory;
public class Activator implements BundleActivator {
 public void start(BundleContext context) throws Exception {
  FrameworkFactory ff = ServiceLoader.load(FrameworkFactory.class).iterator().next();
 }
}

I have the jar org.apache.felix.framework-4.4.1.jar in my bundle. MANIFEST.MF entry :

...
Bundle-ClassPath: .,provider-0.0.1-SNAPSHOT.jar,org.apache.felix.framework-4.4.1.jar
...

But I get the following errors : I have tried in felix container following is the error :

java.util.NoSuchElementException
    at java.util.ServiceLoader$LazyIterator.next(Unknown Source)
    at java.util.ServiceLoader$1.next(Unknown Source)
    at com.xxxxx.consumer.Activator.start(Activator.java:23)
    at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2154)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2072)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1299)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:304)
    at java.lang.Thread.run(Unknown Source)

Please help me in resolving this issue. I want to load OSGi bundles which are present in my Bundle-Classpath.

Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63
Prashant Onkar
  • 414
  • 3
  • 15
  • "OSGi bundles which are present in my Bundle-ClassPath". I think you have misunderstood something fundamental. You don't put bundles on your own classpath... if you do this, they're not bundles any more. – Neil Bartlett Aug 28 '15 at 04:23

1 Answers1

2

FrameworkFactory can be used to embed and start an OSGi framework in a plain old Java application.

You're trying to use it in a BundleActivator, which will only be invoked within the context of an OSGi framework.

So you would be launching an OSGi framework within another OSGi framework, which is probably not what you want.

Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63