Question

I have prior Java coding experience but not so much knowledge of the whole diverse Java Ecosystem. I have now been tasked to develop a small Karaf plugin for a huge system. This system is utilizing countless of Java goodies: Camel, Karaf, Maven and whatnot. I have some example code that I would need to do some minor changes in and rebuild.

The example is a Maven project (atleast there are a pom.xml) and it should be a Karaf plugin in the end. What is the easiest way to do the changes to the example and rebuild the plugin? I have never used any of the above before and the changes are small so installing and configuring alot of stuff seems a bit overkill.

Where to start? :)

Was it helpful?

Solution 2

I agree with tech-idiot, your best bet is spending some time with the karaf-maven-plugin, but you can also set the bundle up by hand, at least to realize that it could be easily achieved with the help of the maven plugin (specially if you have a lot of dependencies).

A basic OSGI bundle (what you refer as "plugin"), is nothing else than a JAR file with a special plain text file in there, the MANIFEST.MF file.

The MANIFEST.MF describes the bundle, its name, description, how you want to activate it, and what the bundle requires to run (its dependencies, or imports), as well as what it has to offer to the other bundles (its exports).

That's a sample manifest file taken from the wikipedia OSGI entry:

Bundle-Name: Hello World
Bundle-SymbolicName: org.wikipedia.helloworld
Bundle-Description: A Hello World bundle
Bundle-ManifestVersion: 2
Bundle-Version: 1.0.0
Bundle-Activator: org.wikipedia.Activator
Export-Package: org.wikipedia.helloworld;version="1.0.0"
Import-Package: org.osgi.framework;version="1.3.0"

The MANIFEST.MF file is usually packed in the META-INF/MANIFEST.MF folder of your jar, so:

  • You can write that file by hand and add it manually to your generated jar.
  • Probably, from the last three elements of the sample manifest, you'll only need the Import-Package section (no Bundle-Activator and no Export-Package)
  • You should declare in the Import-Package each required external package import for your app and its version. Keep in mind that the external dependencies you use in your app must be available in the OSGI runtime for your bundle to run.

OTHER TIPS

Maven already provides a plugin for karaf , only thing that you have to do is to attach it .

For more reference you can see the below link.

http://karaf.apache.org/manual/latest/developers-guide/karaf-maven-plugin.html

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top