Tomcat and OSGi

user1768830 picture user1768830 · Sep 16, 2013 · Viewed 13.9k times · Source

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!

Answer

Milen Dyankov picture Milen Dyankov · Dec 1, 2016

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.