在Java webframeworks的一系列博客中,它们应该在OSGI中很好地发挥作用, 我正在仔细看看卡拉夫。我的测试用例很简单,部署一个Servlet 在卡拉夫。 OSGI有不同的HTTPService实现,我正在尝试使用Equinox实现(org.eclipse.osgi.services)。
我的bundle很好地加载而没有HTTPService依赖,但是当我为HTTPService [3],Servlet添加依赖项并尝试安装功能[1]时,我遇到了麻烦[2]。
注意:
所以投诉是关于aries-blueprint的,但我不想在我试图安装的软件包中依赖它。
欢迎来自社区的建议!
谢谢你, Christophe Bouhier
[1] Karaf特征名为oss2
<?xml version="1.0" encoding="UTF-8"?>
<features name="oss2-features" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
<feature name="oss2" version="1.0.0">
<bundle>file:///Users/Christophe/Documents/Projects/GIT_netxstudio/plugins/base/com.netxforge.oss2.web/target/com.netxforge.oss2.web-1.0.0-SNAPSHOT.jar</bundle>
<bundle>file:///Users/Christophe/Documents/Spaces/netxstudio/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/javax.servlet_3.0.0.v201112011016.jar</bundle>
<bundle>file:///Users/Christophe/Documents/Spaces/netxstudio/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.osgi.services_3.3.100.v20130513-1956.jar</bundle>
<bundle>file:///Users/Christophe/Documents/Spaces/netxstudio/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.osgi_3.9.1.v20140110-1610.jar</bundle>
<bundle>file:///Users/Christophe/Documents/Spaces/netxstudio/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.equinox.transforms.hook_1.0.401.v20130327-1442.jar</bundle>
<bundle>file:///Users/Christophe/Documents/Spaces/netxstudio/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.equinox.weaving.hook_1.0.200.v20130327-1442.jar</bundle>
</feature>
</features>
[2]错误:
karaf@root(bundle)> feature:install oss2
Error executing command: Uses constraint violation. Unable to resolve resource org.apache.aries.blueprint.core [org.apache.aries.blueprint.core/1.4.1] because it is exposed to package 'org.osgi.service.framework' from resources org.eclipse.osgi [org.eclipse.osgi_3.9.1.v20140110-1610] and org.eclipse.osgi [org.eclipse.osgi_3.9.1.v20140110-1610] via two dependency chains.
Chain 1:
org.apache.aries.blueprint.core [org.apache.aries.blueprint.core/1.4.1]
import: (osgi.wiring.package=org.osgi.service.framework)
|
export: osgi.wiring.package: org.osgi.service.framework
org.eclipse.osgi [org.eclipse.osgi_3.9.1.v20140110-1610]
Chain 2:
org.apache.aries.blueprint.core [org.apache.aries.blueprint.core/1.4.1]
import: (&(osgi.wiring.package=org.apache.aries.util.tracker)(version>=1.0.0)(!(version>=2.0.0)))
|
export: osgi.wiring.package=org.apache.aries.util.tracker; uses:=org.osgi.service.framework
org.apache.aries.util [org.apache.aries.util/1.1.0]
import: (&(osgi.wiring.package=org.osgi.service.framework)(version>=1.0.0)(!(version>=2.0.0)))
|
export: osgi.wiring.package: org.osgi.service.framework
org.eclipse.osgi [org.eclipse.osgi_3.9.1.v20140110-1610]
[3]服务
@Component
public class WebDude{
private HttpService httpService;
@Activate
public void activate() {
try {
httpService.registerServlet("/dudeme", new WebDudeServlet(), null, null);
} catch (Exception exception) {
exception.printStackTrace();
}
}
@Reference
public void setHTTPService(HttpService httpService) {
this.httpService = httpService;
}
class WebDudeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("I am dude");
}
}
}
答案 0 :(得分:1)
您正在安装org.eclipse.osgi_3.9.1.v20140110-1610.jar,这是一个OSGi框架本身。您永远不应该将框架包安装到现有框架中。
相反,切换karaf使用equinox。在etc / config.properties中设置:
karaf.framework=equinox
然后从您的要素文件中删除上述包。您甚至可以通过使用HttpService和DS的karaf功能来缩小功能:
功能:安装scr http
所以也许在那之后你可以直接安装自己的包。