views:

383

answers:

2

Hello,

I am pretty new to the whole Java and OSGi world and I have trouble understanding the eco system of a OSGi web application.

To be more precise I am at the moment trying to understand how all the parts of the eco system are related to each other:

  • OSGi Framework (e.g. Apache Felix, Equinox, Knoplerfish)
  • OSGi Runtime (e.g. Spring DM Server, Pax Runner, Apache Karaf)
  • Web Extender (e.g. Pax Web Extender, Spring Web Extender)
  • Web Container (e.g. Apache Tomcat, Jetty)

To give you a visual representation of my actual understanding of their relationship check out this image:

alt text

As far as I know the OSGi Framework is a implementation of the OSGi specification. The runtime is a distribution which adds additional functionality on top of the OSGi specification like logging for instance. Since there seem to be some differences in the classpath mechanism of OSGi and web containers like Tomcat you need some kind of translator. This part is handled by the "Web Extender".

Would you please clarify this whole thing for me? Am I understanding everything correct?

+5  A: 

OSGi is a standard in terms of API and packaging for interacting software modules. This is similar to other API standards like JPA or JEE.

An OSGi runtime is a server which follows the OSGi standard, it is an implementation of the standard. You mention some common ones: Knopflerfish, Eqinox. These let you run OSGi bundles.

A web container usually refers to an implementation of the web-specific parts of JEE (servlets). The servlet standard also defines an API and packaging, just like OSGi, only different.

You need a server to run your JEE web apps. You package your app as a Java Web Archive (WAR), and ask your application server to start it. There are several servers, as you mention, like Tomcat, Jetty, but also bigger servers which cover larger parts of the JEE standard, like Glassfish and JBoss.

A web extender tries to unify the servlet standard with OSGi. By adding some OSGi-specific data to your already packaged WAR, the WAR will be automatically parsed and started by your OSGi runtime. Your WAR servlets will be published to the OSGi http service by the web extender. With a web extender, you can run both standard OSGi applications as well as WARs using only a OSGi runtime, without the need for a JEE-compliant server like Tomcat.

disown
Thank you for your quick response disown. If I understand you correctly the web extender takes WAR files, which would be normally deployed to a web container like tomcat, and would make them run on the OSGi runtime. The OSGi HttpService would then make them available "on the web" via the HTTP Protocol. Correct? In conclusion: I would not need a Web Container like Tomcat?
Jens
Yep, precisely right about how it fits together. You'r services will be made available through the OSGi http service. However, in practice, the web extender uses a web container in order to deploy the WAR anyway. The benefit you get is that the WAR can be started with your normal startup scripts of the OSGi framework, and the WARs can take part in the normal dependency management of the OSGi framework (i.e you can depend on WAR:s, and WAR:s can depend on other OSGi bundles).
disown
And all servlets will be registered to the OSGi http service.
disown
Thank you for your answers. That has helped me a lot! I gave you a up vote and marked your response as an answer to my question. Again, thank you.
Jens
Wow, this is the best description of how Tomcat and OSGI fit together! Do you mind taking a look at my question? http://stackoverflow.com/questions/3893494/integrating-equinox-osgi-into-apache-tomcat-web-app
drozzy
+1  A: 

Jens,

As I have some experience with OSGi, I really would not suggest you start with plain OSGi.

Start with Eclipse RCP (Rich Client Platform) instead.

You not only get a OSGi runtime, but a full-featured integrated IDE if you download Eclipse IDE for RCP and RAP Developers edition here.

Lucky for us all, you can get the book Eclipse Rich Client Platform (2nd Edition) which was recently released only a few months ago and contains updated info/guide on Eclipse RCP.

OSGi is the fundamental building blocks of Eclipse RCP, however OSGi by itself is confusing and boring (at least for starters). Getting up to speed on Eclipse RCP is much easier and enjoyable, you can build a functional "do-something" app within hours.

With plain OSGi, you'd already be lucky if you can get rid of ClassNotFound exceptions within the first few days.

After some time with Eclipse RCP, "convert" your app to Eclipse RAP to run it as a web application on a Java servlet container. See if you like it, even if you don't... by this time you'd have already grasped the OSGi concepts & practices that your sailing to "plain OSGi" would be somewhat smoother than if you had started from scratch.

Good luck Jens!

P.S. I also write about this stuff on my Java EE blog, though not always specifically on OSGi.

Hendy Irawan
Hey Hendy, thank you for your reply. I guess I am not the ordinary coder since I thought plain OSGi is not that bad at all. And I made most of my training projects only using my terminal/console and a simple text editor ;) I like to keep things simple. But the whole Eclipse environment is of course not bad either and for larger projects the way to go. I don't know why all OSGi coder are so ashamed of plain OSGi? In my eyes it made Java interesting again.
Jens
Just wanted to add my 2 cents here. I disagree with Hendy's advice about not looking at or using plain OSGi. There are many cases where plain OSGi, or some other OSGi components are a far better option than RCP. Surely RCP has its uses, but it's not the silver bullet.
Marcel Offermans
@Marcel thank you, I certainly agree with you that "RCP has its uses, but it's not the silver bullet."What I meant is that Eclipse RCP is an easier way to get started (i.e. **learning phase**) with OSGi. Within a few days a programmer will be able to do many things relatively easier than with plain OSGi, then get a "feel" for what OSGi is.A blank programmer starting from plain OSGi would probably catch too many errors the first few days, and easily confused.After the initial curve is passed, it's then developer's choice whether RCP or plain OSGi is better for their project.
Hendy Irawan
Whats the difference between Eclipse RCP and Equinox?
drozzy
@drozzy Eclipse RCP is a rich client **platform** (hence the name) that runs on top of OSGi runtime called Equinox. Equinox is just the OSGi runtime. Perhaps a good tech analogy is Eclipse RCP is the GUI and Equinox/OSGi is the kernel.
Hendy Irawan