What exactly is Apache Karaf? - osgi

I am a little bit confused about what Apache Karaf exactly is.
Can you say that Apache Karaf includes, amongst other things:
Apache Felix (which is an implementation of the OSGi 4.2 framework)
Apache Aries (which is an implementation of the Blueprint standard)

TLDR: Apache Karaf is much more 'batteries-included'. It can also run on any OSGI runtime.
Apache Felix (which is an implementation of the OSGi 4.2 framework)
Sort of. Apache Karaf can use Apache Felix. Apache Karaf can also use Equinox or another OSGi runtime. By default, the Apache Karaf standard download does come with Apache Felix.
Apache Aries (which is an implementation of the Blueprint standard)
Again, sort of. The standard download of Apache Karaf does come with Apache Aries by default.
Now let's talk about what OSGI (Apache Felix, Equinox) is and what Apache Karaf is:
OSGI is very simple. You can start an OSGI runtime in your application and not even notice it. The shell, the ability to hot deploy from a folder, install from a maven repo, etc..These are all extras that OSGI doesn't have to do and are provided by additional projects like Karaf, GOGO, or Pax
Now on to Apache Karaf:
It is basically an OSGI environment that provides some additional goodies on top of a standard OSGI implementation. Because Apache Karaf is just built on standard OSGI, it can in theory run on any OSGI runtime. This gives you a uniform interface for working with OSGI runtimes.
Some goodies Apache Karaf provides that you won't see in a Apache Felix without some additional work:
Folder based hot deployment
A (IMHO) better default console than gogo. (org.apache.karaf.shell)
Remote SSH access to that console. (org.apache.karaf.shell.ssh)
Centralized Logging System. (org.apache.karaf.log)
It has it's own way of provisioning bundles and start levels. (org.apache.karaf.features)
Karaf has it's own maven plugins as well.
Pretty much anything here:
http://mvnrepository.com/search.html?query=org.apache.karaf*
I mentioned Karaf having it's own way of provisioning bundles and start levels. Apache Karaf also comes with a bunch of pre-defined ones to get started with. I know Apache Felix comes with some as well, through OBR, but Apache Karaf comes much more 'batteries-included'.

Apache Karaf is a swiss army knife to run OSGi "stuff" and non OSGi things bundled as OSGi.
Felix and Aries are default but the frameworks are pluggable, so equinox works as well.
"Unix like" shell accessible from CLI or SSH
Hotdeploy of bundles
May deploy almost anything as a bundle (plain .jar, spring xml, blueprint, etc)
WAR files
Deploy from maven - including autowrapping non OSGi bundles.
Web Console
Karaf features - ".kar files" that includes bundles and custom karaf features/commands.
A side note is that Karaf is part of ServiceMix (the initial name was ServiceMix kernel), so it has very tight integration with Apache Camel, Apache CXF and Apache ActiveMQ. Turning Karaf into an ESB with those features is trivial.

Apache Karaf is just an OSGi framework (it can be equinox, felix .etc) with a bunch of predefined modules.
Apache Karaf architecture:

Related

Can I deploy a fab bundle on any OSGI-compliant container/application server?

I am currently trying to deploy my camel app as a FAB bundle in the Fuse ESB container. I understand that I can install Fab(Fabric-bundle) as a feature on OSGI containers like Karaf or felix and deploy the bundle. I want to know if this feature is available on all OSGI containers as well as other application servers like IBM Websphere(Websphere supports OSGI) or will this tie me up to the Fuse ecosystem.
Will deploying as a WAR or an OSGI bundle be a better approach as the goal is to support as many ESB Containers/Application Servers as possible.
No, this is a specialty of Fuse, for this it'll only work on the FUSE containers. Even Vanilla Karaf doesn't understand FAB (unless it's a standard Karaf feature, with just another name to it)
For usage of Karaf Featurs outside of Karaf you'd need to add the feature resolver and services of Karaf to the other OSGi containers first. Never tried that but might be possible.

deploy Apache ServiceMix 4 application into JBoss Application Server 7

I have an standalone Apache ServiceMix 4.4 application, it works nicely. Now, I want to deploy this application inside a JBoss Application Server 7. I use Maven as project and dependency management tool.
My objective is deploying the application not touching any line of code, only maven POM files. I can add new dependencies, change some versions (minor) and use different tools. I want, as a second objective, integrate all the Apache CXF DOSGi container features into JBoss AS ones seamlessly.
I think it is possible, but I found information for old releases of JBoss and ServiceMix or incomplete guides like this.
Can someone provide more information about that?
EDIT
I have found some issues in JBoss issue tracker:
Initial runtime support for Karaf based products
And some JBoss forum topics:
Migrating osgi bundles running in Karaf to JBoss 7 as OSGI container
I forgot to mention that my application is using Apache Karaf OSGi runtime.
Well Servicemix is "pre-"setup of a Container (Apache Karaf) and lot's of other Apache Projects like ActiveMq and Camel plus some ServiceMix specialties. So why would you want to deploy this setup in another Container?
If you want to do something like this, try to deploy std. Apache Camel, ActiveMQ and CXF and your own app in JBoss.

How to run ActiveMQ in a OSGi Felix container?

Hi I would like run ActiveMQ inside the Apache Felix OSGi container. I don't want to run it as an embedded broker, in other words I don't want to have to write code. The ideal situation would be just to deploy the AMQ jars inside Felix and change config files to modify its behavior.
It looks like this is posible with the Apache Karaf container, but I cannot find neither documentation on how to do it in felix nor a clear answer if this is possible.
Thanks.
It looks like you are looking for Apache Service Mix
= Apache Karaf with ActiveMQ + Apache Camel + Apache CXF + other nice stuff.
But if you rather do it yourself, you could stick with Karaf or Felix, can't you just take the ActiveMQ bundle and do it similar to this instruction?
http://activemq.apache.org/osgi-integration.html
If you really want to deploy ActiveMQ in pure Apache Felix then the best way to start is to look into the Karaf feature for ActiveMQ. You need to install all the bundles referenced there and some basic karaf bundles.
In the ActiveMQ Karaf feature the broker is started using a Spring or Blueprint deployer from Karaf. This will look for spring dm or blueprint files and start them. The broker config is then such a file that starts the whole ActiveMQ.
So with some effort it should be possible but in the end you will duplicate a lot functionality of karaf. So using Karaf in the first place like Petter suggests is the simpler way to go.

OSGi bundles and wars

Is it possible to have standard war deployment, which can be deployed on tomcat and also can be build as OSGi bundle and deployed with other bundles in OSGi container tomcat(i think virgo)?
Yes, there's a good deal of interoperability between WARs and WABs. Apache Aries and WebSphere Application Server will convert WARs to WABs on deployment. This is a good way to get up and running, but it's a better practice to use proper WABs in which you build in the OSGi metadata yourself. The extra OSGi headers won't interfere with the deployment in a normal Tomcat container, so the WAB has the greatest flexibility.
For your build, you have a number of options. For example, the maven bundle plugin can be configured to build WABs, or you can use Eclipse PDE's tooling support for OSGi metadata.
Pax-Url-War provides this functionality to containers like Apache Karaf. In brief, this allows you to import an URL like war:file:///path/to/myapp.war and Pax will wrap it as an OSGi bundle, optionally changing the URL root and other parameters on the fly.

OSGi: What are the differences between Apache Felix and Apache Karaf?

Apache Karaf is a sub project of Apache Felix. It is defined as "a lightweight OSGi container".
I don't understand when should I use the heavyweight and when to use the lightweight. Their site doesn't explain this too much.
The 'lightweight OSGi container' label is contrasting Karaf with more feature rich OSGi containers, not with Felix.
To quote Guillaume Nodet (Karaf's author) from here:
Felix is just the OSGi core runtime. Karaf provides a "distribution" based on Felix by adding other features such as a console, an SSH remoting mechanism, a file deployer and more.
In this diagram of the Karaf architecture, Felix (or other OSGi implementation - currently Equinox is also supported) is the OSGi box, the other boxes are the features added by Karaf:
Therefore, unless you have specific needs which are not met by Karaf (requiring access to the underlying implementation) it usually makes sense to use this since it provides more 'out of the box'.
#Marcel
Karaf isn't monolithic or huge like a Java EE server. It is a very slim and minimalist implementation. It is a core product without much functionality other than a basic console, file loading so that you can actually read configuration files, etc. The latest zip file of it is 19.1 MB. Yeah. Small. It can easily run on small devices and work in embedded.
What you may be thinking of is something more like ServiceMix which uses Karaf as a core/kernel. But it includes CXF, ActiveMQ, Camel and other libraries in its full configuration. Even then they have minimal, medium and full sizes.
Really, for 99% of the projects out there it wouldn't make sense to start directly with Felix and not use Karaf instead.
Currently, there are three popular open source OSGi containers:
- Equinox. It is the modular Java runtime at the heart of the Eclipse IDE,
- Knopflerfish, Is an open source implementation of the OSGi R3 and OSGi R4 specifications.
- Apache Felix. Is the open source OSGi container from the Apache Software Foundation.
http://www.javaworld.com/article/2077837/java-se/java-se-hello-osgi-part-1-bundles-for-beginners.html
The Apache project maintains a general-purpose OSGi container called Felix.
Here is used as ServiceMix and
The main difference between the ServiceMix and Karaf is that
ServiceMix bundles a bunch of other integration components — ActiveMQ
message broker, the Camel routing engine, and some other things
According: http://kevinboone.net/osgitest.html

Resources