To understand Apache Karaf, you should first know about OSGi.
Java applications are deployed in the form of Jar files as their artifact. If the application depends on other jar files, then those jars must be present on the application's classpath. When application runs, required classes are loaded and instantiated as required.
If your application is deployed inside any container (e.g: a web server like tomcat), then the container follows some standard logic for loading or initializing your application. This involves loading the classes. It is required that classes referred inside a program must be present on the classpath of the application(e.g: the web-inf directory of your war file).
If the container does not find the required classes inside the war, it consults the application 's parent classloader to locate the class files.
So, this way multiple hierarchical classloaders comes in picture while working with normal java runtime.
This has a problem that the same class is loaded multiple times depending on the applications deployed.
Welcome to the OSGi.
In OSGi a jar will be called as a Bundle.
A bundle looks similar like a jar but with extra headers in its manifest.mf file.
The headers provides the information about what packages are exported/imported by the bundle.
When your application wants to use any library jar file, you mentions the required packages in the manidest 's Import-package header.When any other bundle wants to use packages inside your bundl,you must expose the package using Export-package header.
An OSGi runtime looks for such headers and handles class loading efficiently. So, a class will be loaded only once using its jar's classloader only and you will be rescuid from annoying ClassNotFoundExceptions.
OSGi is the specification. It has a list of headers that can be used inside manifest.mf. Period.
Apache Felix and Eclipse equinox are few of the implementation of this specification.
Apache Karaf is a console. A console helps in interacting with any application. Here, the application is OSGi runtime which is Apache Felix.
Karaf provides lot of commands to interact with OSGi. You can deploy new bundle to the OSGi at runtime ( no need to restart the Karaf) using its hot deploy feature. Just put the bundle file in deploy folder and you are done.
With Karaf, you can see services, packages exposed by any bundle. Karaf provides lot of out of the box frameworks like spring, jetty server , logging utilities.
With Karaf you can start, stop any bundle during runtime.
So, to conclude , Karaf is just a console for OSGi runtime.
You can write any normal java programs and play with OSGi. You just have to hook up your application initialization logic with bundle activator.
Apache maven is a build tool. With this, you can build( prepare jar artifact) any java project.
While working with OSGi you need to adhere with manifest.mf symantics. Packages should be exported and imported as required. To help with building the appropriate manifest.mf , there is a 'bnd' tool. This tool analyses your application's classpath and prepares final OSGi bundle with appropriate manifest .
Apache maven makes use of this 'bnd' tool with its maven-bundle-plugin.
Just attach this plugin to the project's life cycle goal and you are done. Maven will prepare a bundle for you.