Artifacts with jar packaging which could be become bundles too accordind to some profile - osgi

I would like to ask you some hints about the proper way to configure maven in the following scenario:
I have some artifacts which are currently packaged as jar, but they have maven-bundle-plugin too because I want them become OSGI bundles, nevertheless I didn't change their package to bundle because it exists the case that I want build them as jar (or war sometimes).
To use maven-bundle-plugin with package jar I have followed this chapter and all worked fine, but now I'm considering to package them with bundle, to gain the full features of maven-bundle-plugin and because my default deploy is to OSGI.
So I would like to know if packaging artifacts as bundles but using them in a not OSGI container may results in troubles, what do you think? Thx

If you build your bundles using the alternative and newer plugin bnd-maven-plugin then it is not necessary to change the packaging type.

Related

What is the recommended usage pattern for karaf-maven-plugin?

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.

Maven: Jar with dependencies VS jar without dependencies

I am currently working in a Java project, and we use maven to build the final jar. There are two ways to build the jars as we all know, i.e. one single jar with-dependencies, and a jar without dependencies. In the latter case, we need to add dependent jars to the classpath as well.
In principle both can work, personally I prefer one jar with dependencies, but in the project team members decided to use separate jar without dependencies. So hereby I would like to know which choice is better?
This question has no answer, since it depends on what you need to do.
If you're writing an utility package or component, that could be a dependency of another project, then there's no point in having all the dependencies inside it - it's better to leave dependency resolution to a dependency manager, like Maven.
If you, instead, are writing a full application packaged as a jar, I mean something with a MainClass that can be executed with java -jar myjar, then having the dependencies together will make distribution easier.
Consider that, for instance, if you're writing a webapp, that'll be packaged as a WAR, it normally comes with dependencies.

Reference a eclipse plugin from a regular project

this is a more conceptual question:
I want to create an application which uses the WALA framework, which itself is packaged as a eclipse plugin, built with maven-tycho. When I try to add this as an dependency no transitive dependency gets resolved, because they are covered by the tycho build.
This is the pom of the WALA project I need at least https://github.com/wala/WALA/blob/master/com.ibm.wala.core/pom.xml
Should my application be a OSGI Bundle itself or can I create a regular jar with it without having much trouble? Which approach is more practical?
If I have seen it correctly, wala.core has only two dependencies wala.util and wala.shrike (util has none, shrike depends on util). So you might as well simply include all three dependencies in your project.
On the long haul, however, you might should indeed consider creating an osgi application instead.

Alternate solution to the Maven Shade plugin in order to deploy a list of shared libraries in the Cargo plugin?

I need to execute non-regression tests on a system made of a set of Web Applications and shared libraries. I currently use the Maven Cargo plugin in order to deploy this system on an Apache Tomcat Web Container.
Up to now, the shared libraries, which are also used in the production environment, were referenced in a Maven BOM file, and then "imported" by other Maven projects. For instance, they are imported by the Maven projects that take care of the distribution of the software.
However, this approach does not work with the Cargo plugin, because this plugin seems not to support the import of the materials declared in a BOM file. As a workaround to this issue, I've used the Maven Shade plugin in order to produce an "uber" jar with all these shared libraries. This is working perfectly well, but I'm not 100% satisfied with this workaround, for the same reasons as those reported in What is the maven-shade-plugin used for, and why would you want to relocate java packages?
As there any other alternate approach to this issue (EAR not supported in our environment) ?

Using OSGI bundles with sbt or maven

I had this crazy idea since a long time so decided to finally ask. Is there some project for integrating bundles directly into the the build process without explicitly doing extra work of including an osgi container and adding bundles etc. So the basic idea being in you build.sbt or pom.xml you just specify your dependency like you normally do and instead of fetching the jars, sbt or mvn fetches bundles (if available) for your dependency. And on building the project a container of your choice would be downloaded and bundles (and jars) would be added to it automatically ? Just like a fairy tale.
EDIT: By the last part i meant something along the lines of felix gogo which will create a script for adding bundles to run container with them. Althogh thats too much to ask for but after the build i can just run a script and my whole project will run on an osgi container free from jar hell.
This already works today. You simply use the maven bundle plugin to create a bundle of your code during the build process. Many of the jars in maven central already are bundles. So you just specify them as normal dependencies.
I am not sure what you want to achieve in the last part. Downlaoding the container and adding the bundles. The build process just creates the jar. Why should it load a container?
If you want to do this for testing purposes then pax exam is what you search. It does exactly what your describe for your unit tests. It downloads a container, adds your bundles and deploys and runs your test in the container.

Resources