Jena OSGi bundle cannot start - osgi

I want to use Jena OSGi 3.0.0 version in Felix 2.0.3, but when I install the bundle I get the exception:
Unresolved constraint in bundle org.apache.jena.osgi [1]: package; (&(package=org.apache.commons.cli)(version>=1.3.0)(!(version>=2.0.0)))
Does this mean that the package org.apache.commons.cli is not contained in the jena-osgi bundle?
Any ideas how to solve this issue?

Yes, this means that the jena-osgi bundle imports package org.apache.commons.cli. You need to install the bundle that exports this package.
Funnily enough, this package is exported by a bundle named org.apache.commons.cli which you can get from Maven Central:
http://search.maven.org/#artifactdetails|commons-cli|commons-cli|1.3.1|jar

Related

Hystrix and OSGI bundle

I have used org.apache.servicemix.bundles.hystrix dependency to bundle Hystrix as OSGI bundle. However, I'm facing this issue:
org.osgi.framework.BundleException: Could not resolve module: [828]
Unresolved requirement: Import-Package: com.netflix.hystrix; version="[1.5.0,2.0.0)"
Can someone help me on this?
Thanks!
The error tells you that the bundle you try to install and resolve requires a certain package and that there is no bundle that offers this package.
So in you case the package com.netflix.hystrix is missing. This means that you either do not have the hystrix bundle installed or you installed a version that does not match the version range [1.5.0,2.0.0).

Apache karaf how to easily install bundle from Maven repo

I am trying out Karaf and installed some bundle X. This bundle X complains about a missing requirement: Unresolved requirements ... osgi.wiring.package; (osgi.wiring.package=org.apache.commons.httpclient)]
Hence, I tried to provide the org.apache.commons.httpclient through bundle:install mvn:commons-httpclient/commons-httpclient/3.1 which worked.
But, after trying to start the X again, I still get the same error message.
thanks!
That jar is not a bundle, hence can't be deployed to karaf, it's just ignored.
Try
karaf#root>bundle:install -s mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient/3.1_7
Make it sure that your bundle has in their META-INF/MANIFEST.MF the osgi import declarations syntax. I assume that you use bndtools to generate the bundle.
Agree with #Antonio, for third party libraries which are not OSGi bundles you can also try to install them with wrap:
bundle:install -s wrap:mvn:commons-httpclient/commons-httpclient/3.1
This will create a basic OSGi MANIFEST for the library...
You can find more info here: http://karaf.apache.org/manual/latest/developers-guide/creating-bundles.html

How to access a class from a bundle of lower version?

I have two OSGi bundle with same name. But there versions are different. Suppose one bundle has version 1.0 and another one is 2.0 . as 2.0 is higher version so its priroty will be first. But I want to use a piece of code from bundle 1.0 also. How can I achieve this ??
The bundle version is not reall important when OSGi selects where to import a package from. The only limitation there is that you can not install two bundles with the same symbolic name and version.
What you need is to version the packages the bundles export. Each of the packages can be exported with a different version if you want. In the client bundle you can then import each needed package with an allowed version range.
So bundle 1.0 can export package a in version 1.0 and package b in version 1.1.
Bundle 2.0 can export package a in version 2.0 and package b in version 1.2.
In the client bundle you could then
import package a with a version range of [1.0,2.0) -> would resolve to package a from bundle 2.0
import package b with a version range of [1.1,1.2) -> would resolve to package b from bundle 1.0
You can only do this on the package level though. So you can not access classes that are in the same package from different bundles - at least not without fiddling with classloader... which you should avoid.

Activation error when installing a bundle in OSGi

I am getting the following error when installing a bundle.
Failed to start bundle x.y.z-1.0.0, exception activator error org/osgi/framework/BundleActivator from: java.lang.ClassLoader:defineClass1#-2
How can I get rid of this ?
The easiest way to get rid of the message would be to not install the bundle :-)
It sounds like the bundle's activator class depends on a class the bundle cannot load. So perhaps the desired class was not properly packaged in the bundle or the necessary import package clause is missing.

Apache Sling: unresolved package after Installing SlingShot sample bundle

I am Unable to run slingshot sample , apache sling i have followed these steps
Click here!
the package got installed but it didn't get activated. The detail collapsed view of bundle shows
org.apache.sling.api.resource,version=[2.2,2) -- Cannot be resolved
Your bundle import org.apache.sling.api.resource,version=[2.2,2) was not resolved.
Assuming that your sling installation is running, you should verify if the package org.apache.sling.api.resource is either not exported or exported in the wrong version.
If the package is present then adapt your import.
You didn't indicate how you built or started the Sling instance where you installed the Slingshot bundle.
I just tried with a Sling launchpad built from the launchpad/builder folder of the Sling source code, the Slingshot bundle starts without problems and the /slingshot/albums.html path mentioned in the sample's README.txt works.

Resources