在一系列关于 Java 网络框架的博客中,应该在 OSGI 中很好地发挥作用,我正在仔细研究 Karaf。我的测试用例非常简单,在 Karaf 上部署一个 Servlet。OSGI 有不同的 HTTPService 实现,我正在尝试使用 Equinox 实现 (org.eclipse.osgi.services)。
我的包在没有 HTTPService 依赖项的情况下很好地加载,但是当我为 HTTPService [3]、Servlet 添加依赖项并尝试安装功能 [1] 时,我遇到了麻烦 [2]。
笔记:
- HTTP 服务本身是使用 OSGI DS 服务安装的 [3]
- Karaf 配置为使用 Equinox OSGI impl。
所以抱怨是关于 aries-blueprint 的,但我在尝试安装的捆绑包中没有依赖它。
来自社区的建议将是最受欢迎的!
谢谢你,克里斯托夫·布希耶
[1] 名为 oss2 的 Karaf 功能
<?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");
}
}
}