I am new to OSGI framwork So this question might seem silly.
Can we run Apache Nutch 1.4 in OSGI framework. I want to create an OSGI bundle of nutch. I am using eclipse indigo to compile the Nutch source code. So i think there should be some kind of plugin which can create OSGI bundle instead of jar after the compilation. I just need the OSGI bundle of Nutch.
I don't even know if it is possible.
You need to look for a bundle that implements Nutch. A quick google turned up this. If this particular bundle doesn't meet your needs, you can just embed the Nutch dependency into one of your own bundles, using the Embed-Dependency field in your bundle's manifest.
A bundle which already implements Nutch, as the other answer suggests, is your best bet. More generally, you can easily convert an existing jar into an OSGi bundle (without having the source code) using the wrap function of the bnd tool. If you do have the source code and want to recompile, maven's bundle plugin and the bundle packaging will generate bundles.
In the interests of modularity, which is one of OSGi's main drivers, I'd suggest using a separate Nutch bundle rather than embedding the dependency.
Related
I have a bunch of java classes and a bundle activator class that I need to deploy to karaf.
I see that the karat-maven-plugin has kar packaging and karaf-assembly.
Also it generates features.xml
I can generate features.xml directly and it generates lines with wrap: for some of my dependent non-osgi jars.
But when I run karat-assembly, I run into the issue of the assembly goal not realizing that these jars are not osgi and end up with errors.
What it the recommended way to get a custom karaf with my application installed ?
Does the karat-assembly packaging need to have a features.xml generated and provided beforehand ? Or is it supposed to do the feature set generation by itself ? If it is the latter, then how do I get around the problem of the karat-assembly not recognizing non-osgi jars ?
I have spent a LOT of time with google and am stumped.
This is my procedure for creating a custom karaf distribution. It may not be "best practice" but it works for me. Maybe you can customize for your needs.
After developing my Camel routes and testing I generate my feature file based on a feature template found in /src/main/feature/feature.xml. The karaf-maven-plugin will generate the feature will in the feature folder inside /target.
I do a clean deploy to our maven artifactory.
I have a custom Karaf project do a clean install on that project. The project has dependencies to the initial project and I add all the features as boot level feature.
Once build I unzip the distribution and run the Karaf app. If everything looks ok its ready to be shipped.
I'm trying to build an application that uses an embedded OrientDB (currently "memory:") graph database.
I'm using OrientDB 2.2
I am using Eclipse bndtools for my development environment.
I have added orientdb-core and orientdb-graphdb osgi bundles as build dependencies to my bundle, but on its own that isn't enough, I need access to the tinkerpop blueprint classes as well. There doesn't seem to be a tinkerpop blueprints osgi bundle that I can see.
I can include the blueprints-core jar as a build dependency, and that gets rid of the compile errors, but I then get into all sorts of issues trying to resolve the bundles so I can run something. (the primary error there that I don't seem to be able to get rid of is a complain about not being able to resolve "com.carrotsearch.hppc" -- I include that in my bundle, and export it, but still no joy there)
Shouldn't orientdb-graphdb either depend on a suitable bundle, or include and export the classes?
It sounds like you're running into the classic problem of wrapping a third-party, non-OSGi library as an OSGi bundle.
The best tutorial for this is on the EnRoute site. Note that you don't need to be using EnRoute for this tutorial to be relevant.
We have a very big web application containing many features.Now for maintainability we want to split the application in components so that can remove / add particular components (jars). For that one suggestion is coming is to use OSGI. I think converting jars into bundle will take huge effort. I think same functionality can be achieved by Maven. According to my understanding OSGI is packaging tool. If I can make Maven plug-in for each component then any particular component can be included or removed at compile as opposed to run time as in case of OSGI.
Modularizing the application using Maven will be simpler than OSGI. I have read similar post on this site and it commented that OSGI and Maven are like comparing apple with orange. But I think in one sense both are same as they both meant for packaging difference is one is used at run time and one for compile time
Looking forward for well though answer :)
best wishes
Shailesh
As you already hinted at yourself: you're comparing apple with orange.
OSGi is not a packaging tool.
OSGi bundles are plain JAR files with some OSGi-specific metadata in the Manifest file.
You can create OSGi bundles using Maven e.g. using the Maven Bundle Plugin (I can recommend this approach). So regardless if you're using OSGi or not I strongly recommend using Maven.
Here some use cases for OSGi:
You want to create different versions of your application e.g. for different customers. With OSGi you can just add/ remove bundles without having to touch any other configuration.
You need a plugin system so 3rd parties can provide plugins to your application
You want your application to be truely modular
You want to share some code with other applications but want to hide some internal classes
...
OSGI is much much more than a packaging tool. You could say that OSGI has a packaging tool inside. Maven is a packaging tool and a dependency manager. I'd say that, given the level of complexity and the use you say you'll make of this technology, go with Maven.
I am very new to the OSGi platform.
Having an OSGi bundle B1 that has a dependency to another bundle B2, which is very probably not provided by the container, can I package both bundles in the same jar?
If yes: howto do that? what would happen if the jar is installed and the bundle is already installed?
Yes you can do this... kind of.
Normally OSGi bundles are JAR files because they need to have a META-INF/MANIFEST.MF. The OSGi framework cannot directly read your "multi-bundle" JAR.
However, installing bundles in OSGi involves calling the BundleContext.installBundle method. This method has two flavours, one of them takes an InputStream as a parameter; this InputStream should supply the content of the OSGi bundle. Therefore you can take your big JAR and read it with a JarInputStream, passing the individual entries to the installBundle method.
Although OSGi doesn't directly support multiple bundles in the same jar, there is a standard for multiple bundles in the same archive, which solves the distribution problem you're trying to address. Unfortunately, it may introduce an extra problem in your scenario, because it's part of enterprise OSGi, rather than core OSGi, so it wouldn't be part of a bare bones Equinox or Felix framework. If you have more control over the starting platform your users are using, it may do what you need.
The basic idea is that you package all your bundles into a zip with a .esa extension, along with a simple manifest. You can then distribute the esa file. This tutorial includes lots more detail:
http://coderthoughts.blogspot.co.uk/2013/04/osgi-subsystems.html?m=1
I am working in Adobe CQ5. I made my project that contains only implementation, and the project title is Web Crawler.
And that project is started by one class that simply adds initial seeds.
I made OSGI bundle of my project and I deploy that also.
Now my question is how can I start my bundle, i.e, how can I add seeds ?
For that I read this link that tells me to make Activator class and put your function in the start method. I done the same. But that does not helps me to run the bundle.
Please help me how can I run the given bundle.
Edit No. 1
Can you tell me how can I make MANIFEST.MF file given in given tutorial ?
Look at the bndtools tutorial which is the easiest way to get you started with OSGi
bndtools is a user friendly tool based on Eclipse. With bndtools, you won't get lost in plugin hell. bndtools will also help you avoid BundleActivators since they were not such a good idea, Declarative Services is what OSGi should have been from day one. It also allows you to test the bundles without having to restart.
to create the manifest, if you are using maven (you should) you can use the maven bundle plugin. It will automatically generate a manifest file for you.
Then, to deploy and start your bundle you can use the maven-sling-plugin, which can deploy your bundles into sling.
If you want to manually activate your bundle, CQ5 provides a web based osgi console. you can activate it there. If it fails, there is probably an error in the start method of the activator class.