OSGi got FrameworkFactory could not be instantiated Error

人盡茶涼 提交于 2019-11-28 12:28:00

问题


I am trying to use OSGi and maven to develop an standard alone application.

I have the following osgi dependency in pom.xml

<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.core</artifactId>
    <version>6.0.0</version>
</dependency>

I tried the following code

import org.osgi.framework.launch.FrameworkFactory;

FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();

and got this error message

Exception in thread "main" java.util.ServiceConfigurationError: org.osgi.framework.launch.FrameworkFactory: Provider org.osgi.framework.launch.FrameworkFactory could not be instantiated
at java.util.ServiceLoader.fail(ServiceLoader.java:232)
at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at com.scottfu.ci.test.OSGiTest.main(OSGiTest.java:19)
Caused by: java.lang.InstantiationException:    org.osgi.framework.launch.FrameworkFactory
at java.lang.Class.newInstance(Class.java:427)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
... 3 more
Caused by: java.lang.NoSuchMethodException: org.osgi.framework.launch.FrameworkFactory.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 4 more

what is wrong?


回答1:


The dependency you added is the OSGi Core API.

You need an implementation like equinox, felix or knopflerfish.

E.g.:

Instead of adding the dependency you mentioned, add

<dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.apache.felix.main</artifactId>
    <version>5.6.2</version>
</dependency>


来源:https://stackoverflow.com/questions/42760795/osgi-got-frameworkfactory-could-not-be-instantiated-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!