Tomcat and OSGi
Asked Answered
I

2

14

I was wondering if it is possible to embed an OSGi container like Karaf inside a Tomcat instance. According to this SO question and 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.

So:

  1. 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?
  2. 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.

Thanks in advance!

Indicant answered 16/9, 2013 at 9:46 Comment(8)
angelozerr.wordpress.com/category/java/osgi/equinox/… quite detailed explains how to do it.Pennywise
Thanks @M.Deinum (+1) - interesting that article mentions that they couldn't do this because they were trying to deploy to CloudBees which is a "non-OSGi HTTP Tomcat". I'm trying to deploy on CloudBees as well! (the Java PaaS I mentioned). Do you know how Tomcat can be have OSGi enabled/disabled? Thanks again!Indicant
Not sure where they mention it. But you cannot deploy tomcat as an OSGI bundle but the other way around (OSGi inside tomcat) should work. Drawback is that the Servlet Bridge is quite dated (Servlet 2.4).Pennywise
It's in that article you referenced above @M.Deinum - it's the first paragraph under the section titled "Equinox in a Servlet Container (ServletBridge)".Indicant
That refers to Tomcat as an OSGi bundle... Not to an OSGi container inside Tomcat. He mentions it as the cause for figuring out how to work with the servlet-bride/serverside-equinox.Pennywise
I don't know why people always want to do this, it's like trying to deploy a JBoss inside a tomcat. Karaf is a full Container, not just a OSGi framework, it does provide everything needed to run all kinds of OSGi applications, including WAR/WAB applications. So I still not recommend doing this but if it's really needed you'll need some sort of bridge to the outer tomcat.Ephebe
I agree with Achim. Why do you need Karaf specifically? I can't see it providing any advantages over plain OSGi in this case. Just use an embedded OSGi Framework, don't overcomplicate things.Quaver
I did that here: github.com/enexusde/Karaf-SpringDuong
M
5

Is it possible to embed an OSGi container inside Tomcat?

Yes. In fact if you download Karaf and look in <KARAF_HOME>/demos/web you'll find a demo project that does exactly that.

what system services/ports does embedding OSGi inside Tomcat expose?

That would depend on what you install in it and how you configure it. Here is somewhat old (but IMHO stil relevant) discussion about default ports and how to configure them.

Milburr answered 1/12, 2016 at 21:56 Comment(4)
Funny how this 3 years old question just showed up as new in the RSS feed and tricked me. Oh well I guess since I wrote an answer already I'll just leave it here for future reference.Milburr
after reading web.liferay.com/it/web/milen.dyankov/blog/-/blogs/… today, I found also this post.. compliments @milenOccultation
demo project link is brokenMolybdic
Thank you for reporting it @Molybdic I updated the project link but keep in mind it points to older version of Karaf. I don't know if there is similar demo for the most recent version.Milburr
E
1

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.

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.

Other than the ports you will need a karaf home directory with write access.

Elzaelzevir answered 3/2, 2014 at 11:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.