Java Tomcat 和 OSGi
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18824957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tomcat and OSGi
提问by
I was wondering if it is possible to embed an OSGi container like Karafinside a Tomcat instance. According to this SO questionand a few others, it seems like its possible, but I can't seem to find any solid details on how to do this or what pitfalls/caveats to watch out for.
我想知道是否可以在 Tomcat 实例中嵌入像Karaf这样的 OSGi 容器。根据this SO question和其他一些问题,这似乎是可能的,但我似乎无法找到有关如何执行此操作或要注意哪些陷阱/警告的任何可靠细节。
So:
所以:
- Is it possible to embed an OSGi container inside Tomcat, so that I can hot-deploy OSGi bundles at any point to this container without having to restart Tomcat?
- If the answer to #1 above is "yes", then what system services/ports does embedding OSGi inside Tomcat expose? I ask because I would like to deploy OSGi in a Tomcat server hosted on a Java PaaS where I don't have admin rights. And I'm wondering if - when I try to deploy the embedded OSGi container to Tomcat, that it will try to start listening on ports, or perhaps start doing something to the local file system. If this is the case I will likely receive security/permission errors.
- 是否可以在 Tomcat 中嵌入 OSGi 容器,以便我可以随时将 OSGi 包热部署到该容器,而无需重新启动 Tomcat?
- 如果上面 #1 的答案是“是”,那么在 Tomcat 中嵌入 OSGi 会暴露哪些系统服务/端口?我问是因为我想在我没有管理员权限的 Java PaaS 上托管的 Tomcat 服务器中部署 OSGi。我想知道 - 当我尝试将嵌入式 OSGi 容器部署到 Tomcat 时,它是否会尝试开始侦听端口,或者开始对本地文件系统执行某些操作。如果是这种情况,我可能会收到安全/权限错误。
Thanks in advance!
提前致谢!
回答by 6ton
We deploy our application in the same fashion. We have deployed karaf in tomcat & on weblogic using a servelt bridge. The reason for using the container was to get past environment constraints where some customers are a "oracle" or an "ibm" shop and want all deployments done on these servers.
我们以同样的方式部署我们的应用程序。我们已经使用 servelt 桥在 tomcat 和 weblogic 上部署了 karaf。使用容器的原因是为了克服环境限制,其中一些客户是“oracle”或“ibm”商店,并希望在这些服务器上完成所有部署。
Since you will be using a servlet bridge it does not need to open a new port to list to http traffic. You may have issues with the karaf console if that port is blocked. Also I recall having issues with running cxf due to an embedded jetty instance it starts on another port.
由于您将使用 servlet 网桥,因此不需要打开新端口来列出 http 流量。如果该端口被阻止,您可能会遇到 karaf 控制台的问题。我还记得由于嵌入式码头实例在另一个端口上启动而导致运行 cxf 时出现问题。
Other than the ports you will need a karaf home directory with write access.
除了端口之外,您还需要一个具有写访问权限的 karaf 主目录。
回答by Milen Dyankov
Is it possible to embed an OSGi container inside Tomcat?
是否可以在 Tomcat 中嵌入 OSGi 容器?
Yes. In fact if you download Karaf and look in <KARAF_HOME>/demos/web
you'll find a demo projectthat does exactly that.
是的。事实上,如果您下载 Karaf 并查看,<KARAF_HOME>/demos/web
您会发现一个演示项目正是这样做的。
what system services/ports does embedding OSGi inside Tomcat expose?
在 Tomcat 中嵌入 OSGi 会暴露哪些系统服务/端口?
That would depend on what you install in it and how you configure it. Here issomewhat old (but IMHO stil relevant) discussion about default ports and how to configure them.
这将取决于您在其中安装了什么以及您如何配置它。这是关于默认端口以及如何配置它们的有些陈旧(但恕我直言仍然相关)的讨论。