Karaf Cave vs org.apache.felix.bundlerepository - osgi

Good day.
I am trying to get the benefits of OBR in my application. I took Karaf Cave (4.0.0) as OBR implementation and org.apache.felix.bundlerepository (2.0.4) as OBR client. I successfully configured the repository itself but I can't properly use it.
The problem is: when I install the bundle via OBR and all its dependencies are already installed in OSGI runtime, it is installed successfully. But if some of the requirements are missing, I got an "Unsatisfied requirements" error, which is odd, since I know for sure that all the resources which resolves these requirements are present in the OBR descriptor and all links to them are valid.
Why aren't they resolved automatically? How to configure OBR client to work with Karaf Cave?
I also tried OBR implementation from Sonatype Nexus (OBR plugin) and found out that the OBR descriptor generated by Cave, and the one generated by Nexus, are differ. Moreover:
the one generated by Cave is OSGI compendium spec compliant
the one generated by Nexus is not, but works like a charm with org.apache.felix.bundlerepository - the problem is not reproduced.
I am completely confused.
The step sequence to reproduce the problem (reproduced on Apache Karaf 4.0.0):
1) Installing Karaf Cave:
feature:repo-add cave
feature:install cave-server cave-http
2) Creating a cave repository:
cave:create-repository test
cave:proxy-repository test file:///path/to/some/local/maven/repo
On this step I am able to successfully retrieve an OBR descriptor from
http://localhost:8181/cave/http/test-repository.xml
3) Install the OBR client and register 'test' cave repository from Karaf:
feature:install obr
obr:url-add http://localhost:8181/cave/http/test-repository.xml
4) Try to deploy some OBR resources with obr:deploy

Related

Is it possible to install the karaf server using maven?

I would like to use maven to deploy a complete karaf server including my own features. But so far I am unable to find a way to add the karaf server itself as a dependency. This would save a lot of manual steps, esp. for the other developers which would not have to setup karaf manually.
This would have the added benefit that I do not have to check in the karaf server into the repository in order to have all required parts available from the repository.
Question: is there a way to configure a project using karaf which will setup the karaf server and all required dependencies without manually downloading the files from the karaf website?
This can be done using the karaf-maven-plugin. There is even an example which does this shipped with karaf: examples/karaf-maven-example.
Here is what the examples do
karaf-maven-example-run uses the karaf-maven-plugin:run goal to download and start a Karaf instance.
karaf-maven-example-run-bundle uses the karaf-maven-plugin:run goal to download, start a Karaf instance and deploy the project bundle in this running instance.
karaf-maven-example-deploy uses the karaf-maven-plugin:deploy goal to deploy the module artifact into a Karaf instance (remote for example).
karaf-maven-example-client uses the karaf-maven-plugin:client goal to execute a shell command on a running Karaf instance.
karaf-maven-example-kar packages a features repository as a kar file, ready to be deployed.
karaf-maven-example-assembly uses the karaf-maven-plugin to create a Karaf distribution.
see here for more details.

How to deploy a karaf feature from a local maven repository?

I've created by first project for karaf (4.0.1). So far I've got the following:
an application bundle built with the maven-bundle-plugin. There are going to be more...
a karaf feature created with the karaf-maven-plugin.
a karaf-assembly created with the same plugin
So I'm ready to deliver to the customer - but I'm stuck over the development process. This question answered almost all my remaining questions save one:
After having built my project by running maven install I think I should be able to to get my feature running on a local karaf instance using something like the command feature:install.
I can install my application bundle from local maven by using bundle:install but then I'm down to managing dependencies myself.
Really can't figure out while bundle:install works against my local maven repository and feature:install doesn't.
Found the soloution here. I knew I'd need feature:repo-add - but the name of this command and the official documentation sent me thinking in entirely the wrong direction.
This command does not add a (maven) repository, but adds the location of a feature in the maven repository chain (so I'm thinking the old name addUrl was probably easier to understand).
Anyway - using feature:repo-add mvn:<groupId>/<artifactId>/<version>/xml/features works.
I've just had the similar issue and I've found solution here: http://karaf.922171.n3.nabble.com/Add-additional-local-maven-repository-how-td4028299.html
I've edited the etc/org.ops4j.pax.url.mvn.cfg and uncommented the option org.ops4j.pax.url.mvn.localRepository, setting it to my local repository location:
org.ops4j.pax.url.mvn.localRepository=C:/data/maven-repo
Before installing a feature, you have to register the features repository that provides the feature using feature:repo-add
using feature:repo-add mvn:<groupId>/<artifactId>/<version>/xml

Gradle, OSGi and OBR (or other repository?)

previously I've been using Maven and the maven-bundle-plugin to archive the following:
When doing mvn install, local maven repo contains my bundle + all my bundle's deps automatically
Local repo becomes OBR repository by mvn bundle:index, also repository.xml is automatically updated with every mvn install.
Local repo can now be used for Karaf bundle deployment
Now, I'm looking to migrate some projects to Gradle, which is very nice in many ways. I'm successfully creating bundles using the 'org.dm.bundle' plugin (basic 'osgi' plugin did not allow me to auto-create service components).
By using Gradle's maven plugin I can do gradle install to install my own bundle in local maven repo. I could then use bindex to manually (or through some gradle hacking) index the repo.
However, my dependencies are not put into the maven repo, they are only stored in the gradle cache dir. Thus, I can not use the OBR repo to deploy in Karaf yet.
I've been looking around a lot trying to find some good solution to this, but I have not found anything.
I've looked at Karaf feature files, which would allow me to specify mvn URLs directly instead of relying on OBR, but I'd like to avoid messing with feature files manually.
There are references to using Nexus, but only Nexus Pro supports OBR from what I can see?
I'm up for suggestions on alternative solutions as well; the main goal is that I shall be able to deploy my bundles + deps in Karaf. Maven does not have to be used at all really, although I need some way for different Gradle projects to find dependencies from some other projects (which are not part of the same multi-project).
Any ideas or discussions to put me on the right track is appreciated!
This may be a bit late, but I just stumbled over your question while looking for a way to fetch with gradle from an OBR repository.
As far as I understood you want to push (gradle deploy) to some Maven repository and use it as an OBR repository. This is possible with Eclipse Package Drone, eclipse/packagedrone. You can deploy using Maven/Gradle deploy and let it generate a P2, OBR and OSGi R5 index repository.

Karaf development

Im currently develop bundles for karaf and have some questions...
I wrote a bundle/webservice based on cxf, I try to deploy it in karaf but it could not start that bundle because it could not resolve some packages e.g.
org.osgi.framework.BundleException: Unresolved constraint in bundle org.springframework.aop [56]: Unable to resolve 56.0: missing
requirement [56.0] package; (&(package=org.aopalliance.aop)(version>=1.0.0)(!(version>=2.0.0)))
so here is a question, this package dependency comes from spring-aop (3.1.0.RELEASE), so where is the problem? what dependency is missing? how can I solve such problems?
In that case i did not clearly understand the development process. should i deploy all missing bundles in deploy? because i would like to keep thirdparty libs spereated from my developed bundles. And what bundles i have to deploy? Is it a trial and error process? Is there a common way to let maven do the dependency stuff?
I discovered a folder "system" and read on the docu that it is a repository like maven, is it for the features?
I had for test cases a karaf with some pre deployed bundles and put my webservice bundle into it, but again execeptions...
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet
What dependency is missing?
I already read the tutorial about camel and karaf, but it did not explain the deployment stuff, so could anyone suggest me a good tutorial?
Thanks!
Chris
Short answer
Scroll down to the bit referring to "camel-cxf" and run the two commands features:addurl and features:install. I have a feeling this will resolve all your problems.
spring-aop
On Karaf console type:
exports | grep org.aopalliance.aop
I think you'll see lines like:
XX org.aopalliance.aop; version=3.1.0.RELEASE
So while the spring-aop bundle has the right packages they're the wrong version, the range being requested is >=1.0.0 and <2.0.0, so 3.1.0 doesn't satisfy that.
Deploying/Installing
You can drop bundles into ${karaf.home}/deploy or use the console.
You can install maven bundles from the Karaf console with:
install -s mvn:groupId/artifactId/version/packaging/classifier
Where -s starts the bundle and packaging/classifier are optional.
You can find a lot of OSGi ready maven dependencies here http://ebr.springsource.com/repository/app/ - I had a quick look but your spring aop dependency is very old, what version of CXF are you using?
Read up about Karaf features - they're basically XML files that list suites of bundles that can be installed. Very useful for deploying large numbers of bundles and they can be installed into a maven repository.
There are some standard features available in Karaf, try:
features:install war
This will give you a jetty webcontainer and may resolve your ClassNotFoundException: javax.servlet.http.HttpServlet as long as it's the right version
Camel also has a features file which probably sort all your issues, try this:
features:addurl mvn:org.apache.camel.karaf/apache-camel/2.9.0/xml/features
features:install camel-cxf
Tutorials
There's quite a bit available, some on http://karaf.apache.org and http://fusesource.com but also take a look at the PDF manual that comes in the Karaf distribution.
Always beware that info may be out-of-date
Please post your MANIFEST.MF file. I think you didn't not mention the tag in maven-bundle-plugin dependency.

OSGi bundle repository with plain Maven JARs

I am working on to reach a solution to deploy a web application as a bundle to Virgo 3.0.1.RELEASE. My scenario is:
I use Maven Bundle Plugin to generate the manifest.
I exclude all the JAR dependencies using Maven WAR plugin.
I need to command Virgo to host the plain Maven JAR artifacts in the local repository. As an instance Apache Karaf along with PAX can provide plain JAR files as OSGi bundles.
So,
Any ideas on how to configure Virgo for to host Maven repository plain JARs?
Generally, in your experience, what is the best solution to use a ready Maven repository and host it as an OBR?
Thanks in advance.
The best solution I've found so far is actually using Wrap Deployer on Apache Karaf.
Basically stick with Karaf, since it provides all you need :)
With Karaf and the features you don't really need a OBR, since the features service does a pretty good job of resolving already deployed bundles and won't install those again. You need to add the OBR flag to your features file though.

Resources