Reputation: 424
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.
Upvotes: 0
Views: 567
Reputation: 12865
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.
Upvotes: 2