no osgi ready dependencies - osgi

Currently I'm working with osgi and karaf.
My problem is the no "osgi ready" dependencies , which means a jar that is not ready to be deployed as a bundle into karaf for example.
I tried two solutions in order to deal with this kind of problems :
I tried to to use "Embed-Dependency" which will include the jar
dependency with the project... I don't think this could be a solution
because when I try to embed the jar , it will ask me to include other
jars that the first jar depend on , and so on ..
I tried to convert the no "osgi ready" jars into bundles using bnd tool or from "Plug-in from Existing JAR Archive" from eclipse project.
And this led to the same result , each jar will call another jar that it depend on it..
I am not sure if I'm doing it the wrong way or what is the problem exactly.
Any tips how to deal with no osgi ready dependencies ?

The simplest way to start is to use the wrap: protocol to auto create a jar. Behind the scenes it uses bnd to create a bundle on the fly. Simply prepend wrap: to the mvn url of the jar.
When you try to install the jar using bundle:install -s wrap:mvn:... karaf will tell you which imported packages are missing. Install jars that provide these packages in the same way. The pom of the jar can give you a hint what is missing.
This can mean to install lots of jars if your initial jars has lots of dependencies.
Once you have a list of jars that are installable together you can either create a feature using wrap protocol or you can make bundles from the individual at build time.
In any case you should take a look are the servicemix bundles. It provides OSGi ready bundles for many libraries.

Related

How to convert a maven jar into an OSGI bundle?

How to convert a maven jar into an OSGI bundle? For this jar file, it also has dependencies on other external jar files. I tried maven-bundle-plugin, but how to write Import-Package is a disaster for me...... Can anyone help me out?
More specifically, what I want to transform is ProvToolbox https://lucmoreau.github.io/ProvToolbox/, which has several prov packages. So I need to transform them one by one.
Adding import packages is easy using the UI from Eclipse - just open the manifest, and in the Dependencies tab, you can add them.
This explains how to transform a JAR into an OSGi bundle:
link
Here you have a perfect example to create a fat bundle with all transitiv dependecies.
https://github.com/apache/jackrabbit/blob/2.18/jackrabbit-bundle/pom.xml
Notice the following tag:
<Embed-Transitive>true</Embed-Transitive>

Why third party dependency is required exclusively from OSGi container even if I have it in my maven dependencies?

I want to know why OSGi do not respect the maven dependenceis.
I want to create one app in OSGi(AEM). I want to communicate(CRUD) to the database with the help of JPA(eclipselink).
I created maven project with aem-archetype.
Added all required dependencies(of JPA) into my maven project's pom file.
No errors in Eclipse, I built the project via mvn clean install and installed it into AEM(CQ5) via mvn sling:install. All good till now. No Errors.
But when I go and see my bundle in the felix console, I see that it is not Active but in Installed state.The error reported is that it could not resolve the javax.persistence package.
I was puzzled, I searched and I read about it here -
You have to make sure that you place the same version in another
bundle and deploy first. https://forums.adobe.com/thread/2325007
I converted JPA jar to OSGi bundle and installed in my OSGi container, and the error was gone. Great!
But why OSGi is not watching out for the dependencies I wrote in pom.xml of my maven project. Why it needs JPA strictly from OSGi bundle?
Maybe this is due to any architectural benefit, but could anyone please explain me here about this behaviour of OSGi? And why/how this feature of OSGi is useful ?
The <dependency> section of your Maven POM only covers your compile time dependencies. That means when you run Maven to build your project those dependencies are used to compile the source code and build your bundle. Maven itself is not aware of AEM or OSGi or any other platform or framework (e.g. Spring).
Maven just compiles your code.
You, as a developer, are responsible that all those required compile time dependencies are also available at runtime.
What we usually do is to create an AEM content package Maven module and put all of our required third party dependencies (e.g. JPA bundles) into it. This content package is then deployed by Maven so that those dependencies are also available at runtime.
Reason is: what you are adding as dependency is getting added in build path of your project and being available for your classes.When you run mvn install,it checks presence of all dependency and creates a bundle/jar for you.By default this bundle has only your project classes not other dependencies.
You need to check in depfinder whether external dependencies are already there in OSGi container,if not you have to load them in OSGi container either by embedding external dependencies in your bundle with the help of maven-bundle-plugin present in pom.xml or by making a bundle of jar file(I wont recommend that)which you have done.
I hope this helps!

JBoss Fuse vs. standard Maven dependency

I'm just learning OSGi, JBoss Fuse (6.1) and Karaf. How can I use a standard (not bundle) Maven dependencies without changing them?
I have a simple Maven bundle project. It depends on some third party libraries. It uses them via its blueprint.xml . I understand if the manifest.mf marks packages in the Import-Package entry then there have to be installed bundle with Export-Package in its manifest.mf. In my case if I install these standard Maven projects they won't export the required packages. So I've got the "Unresolved constraint in bundle" error message during the installation. Is the Maven Bundle or Shade plugin able to solve this issue? Or if they can't which is the most elegant way to resolve the dependencies?
Somewhere I've read the Jboss Fuse is able to resolve dependencies from the Maven repository. Can I use this mechanism somehow?
Thank you!
This may be a bit late now, but you can do that using features.
<features>
<feature name="wrap_features" version="1.0">
<bundle>mvn:org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1</bundle>
<bundle>wrap:mvn:org.jdbi/jdbi/2.70</bundle>
<bundle>wrap:mvn:com.microsoft/sqljdbc4/4.2</bundle>
<bundle>wrap:mvn:org.springframework/spring-web/4.2.4.RELEASE</bundle>
<bundle>wrap:mvn:org.springframework.security/spring-security-core/4.0.3.RELEASE</bundle>
<bundle>mvn:com.doi.ws/mssql-fragment/1.0.0</bundle>
<bundle>mvn:com.doi.ws/mssql-impl/1.0.0</bundle>
<bundle>mvn:com.doi.ws/doi-services/1.0</bundle>
</feature>
</features>
You install the features before deploying your project to the fuse server using the features command
Meanwhile I found an almost good solution: with wrap: namespace/prefix Fuse automatically generates a bundle during installation:
osgi:install -s wrap:mvn:cglib/cglib/2.2.2
But I still have to install each dependency manually. Is there any way to automatize the installation of dependencies?
Thx!
Use Bundle-ClassPath manifest header.
Make sure all your maven dependencies are available in the final jar file under a single directory called 'lib'.( This can be achieved using maven resources plugin that copies maven dependencies in any output directory).
Use maven-bundle-plugin and customize the bundle manifest Bundle-ClassPath attribute with its element. Add a path to lib folder so that all the plain vanilla jars are available as a part of bundle classpath.

Make OSGI bundle require JAR dependency

I know that when creating an OSGI Bundle I can declare that it needs other bundles to work correctly (in this situation other bundles need to export things that I will import in mentioned bundle).
But what if I need a jar file for a bundle to work?
Is it possible to write this information in MANIFEST.MF? I have the bundle and for some legacy reasons of other bundles that are used my bundle requires usage of a few jar files.
For building this bundle I use maven plugin for creating OSGI bundles (maven-bundle-plugin).
You cannot use normal JARs as dependency of a bundle. You can use only bundles (JARs with OSGI maniifest) as the dependency of a bundle.
You have the following options:
you embedd such jars into your bundle (http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html chapter titled "Embedding dependencies"). This means that that JAR will be inside your bundle, and the manifest will instruct the OSGI container to load the classes from that JAR as well.
try to find the OSGI version of your dependency jar. You can give a try to Spring EBR or to ServiceMix bundles
you create a bundle for each such jar with embedding (1. point) and then you add them as imported package or required bundle (imported package should be favoured).
I would prefer the second point, if not found, then the third.

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