【发布时间】:2015-11-11 06:36:55
【问题描述】:
您如何评价这个解决方案?
让所有这些都在 Apache Felix OSGi 上运行,为您提供轻量级但功能强大的完整 OSGi 解决方案。
安装 Felix HTTP API 和 BASE 然后将 grizzly-httpservice-bundle-2.3.22.jar 复制到你的 bundle 目录。
(如果您想先测试,然后是完整的 Web 控制台)
启动所有服务并确保您的 Web 控制台正常工作。
你要做的是:
将 Jersy 2 RI 目录中的所有库复制到您的 felix 捆绑包目录(可以删除列出为没有真实描述的文件的文件)并将 derby.jar 也复制到该目录。
这是我工作的 Felix 捆绑目录:
aopalliance-repackaged-2.4.0-b31.jar asm-debug-all-5.0.4.jar derby.jar grizzly-httpservice-bundle-2.3.22.jar hk2-api-2.4.0-b31.jar hk2-locator-2.4.0-b31.jar hk2-utils-2.4.0-b31.jar javassist-3.18.1-GA.jar javax.annotation-api-1.2.jar javax.inject-2.4.0-b31.jar javax.servlet-api-3.0.1.jar javax.ws.rs-api-2.0.1.jar jersey-client.jar jersey-common.jar jersey-container-servlet-core.jar jersey-container-servlet.jar jersey-guava-2.21.jar jersey-media-jaxb.jar jersey-server.jar org.apache.felix.gogo.command-0.14.0.jar org.apache.felix.gogo.runtime-0.16.2.jar org.apache.felix.gogo.shell-0.10.0.jar org.apache.felix.http.api-3.0.0.jar org.apache.felix.http.base-3.0.0.jar org.apache.felix.log-1.0.1.jar org.apache.felix.webconsole-4.2.10-all.jar osgi-resource-locator-1.0.1.jar 验证-api-1.1.0.Final.jar
创建一个基本的 OSGi 包...
普通的激活器覆盖方法看起来像这样..(不包括错误检查:)让事情更清楚......但应该添加)
@Override
public void start(BundleContext context) throws Exception {
ServiceReference refHttpService =
context.getServiceReference(HttpService.class.getName());
HttpService httpService = (HttpService) context.getService(refHttpService);
ResourceConfig rc = new ResourceConfig(CHelloResource.class);
ServletContainer servletContainer = new ServletContainer(rc);
httpService.registerServlet(
"/j",
servletContainer,
null,
httpService.createDefaultHttpContext());
}
@Override
public void stop(BundleContext context) throws Exception {
ServiceReference refHttpService =
context.getServiceReference(HttpService.class.getName());
HttpService httpService = (HttpService) context.getService(refHttpService);
httpService.unregister("/j");
}
:)
分配比预期的更简单?加入 JAX-RS 和 OSGi ?
【问题讨论】:
-
我怀疑这个“问题”会在 SO 上得到回答。
-
[...... ;-) ........ ]
-
您对社区的期望是什么?这不是一个技术问题。在您的博客中发布这样的内容作为教程会更合适。
-
欢迎任何反馈。我认为它更针对 OSGi 用户。有时人们有更好的做事方式。这是我的方式。如果有人可以评价它,那就太好了。实施是好是坏?以及为什么。这个问题本身就是一个解决方案。但是有很多方法可以解决问题。
-
问题出在哪里...?
标签: osgi