Maven (Tycho) cannot resolve OSGi Core bundle - maven

I have a dependency on "org.osgi:osgi.core" (7.0.0) in my POM. The reason is that I need access to the "org.osgi.framework" package. I am using Maven (3.6) and Tycho (1.5.1) for building. The build platform runs Debian 10 and Java 11.
I get the following error:
Missing requirement: osgi.core 7.0.0.201802012106 requires 'osgi.unresolvable; (&(!(must.not.resolve=*))(must.not.resolve=*))' but it could not be found
However, if I remove the dependency I get the following error:
Missing requirement: my.bundle 0.0.0.qualifier requires 'java.package; org.osgi.framework 1.7.0' but it could not be found
What is going wrong? How can I resolve this problem?

I get the following error:
Missing requirement: osgi.core 7.0.0.201802012106 requires 'osgi.unresolvable; (&(!(must.not.resolve=*))(must.not.resolve=*))' but it could not be found
The "companion jars" are not meant for runtime and since resolving is a runtime operation (even when performed during build, i.e. for deployment purposes) should not be included (and are therefore marked with the unresolvable requirement).
However, if I remove the dependency I get the following error:
Missing requirement: my.bundle 0.0.0.qualifier requires 'java.package; org.osgi.framework 1.7.0' but it could not be found
This means you have no runtime framework available! Add a runtime dependency on the equinox framework (not intentionally being biased, but since you're using tycho I'm assuming eclipse/equinox landscape. If you have Apache Felix framework available to p2/tycho then use that if you like):
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.x.0</version>
<scope>runtime</scope>
</dependency>
// of course use tycho mechanism for above.

Related

OSGI bundle dependency issue

I have got the project for migration. Currently, version is CQ5.6. Maven build is deploying successfully. However, after build, bundles in osgi show in installed state. Two dependencies causing the issue.
org.apache.felix.shell,version=[1.0,2) -- Cannot be resolved
I was getting an error earlier as below during build.
ERROR
[INFO] --- maven-bundle-plugin:2.3.4:bundle (default-bundle) # myPRJ-taglib ---
[ERROR] Error building bundle com.mypack.deewealth:myPRJ-taglib:bundle:1.0.0-SNAPSHOT : Unresolved references to [org.apache.felix.shell] by class
(es) on the Bundle-Classpath[Jar:dot, Jar:OSGI-INF/lib/recaptcha4j-0.0.8-kohsuke-1.jar, Jar:OSGI-INF/lib/commons-io-2.1.jar, Jar:OSGI-INF/lib/commons-
lang-2.4.jar, Jar:OSGI-INF/lib/crx-packagemgr-1.0.22.jar, Jar:OSGI-INF/lib/squeakysand-osgi-0.4.0.jar, Jar:OSGI-INF/lib/jsoup-1.6.1.jar, Jar:OSGI-INF/
lib/stax-api-1.0-2.jar, Jar:OSGI-INF/lib/org.apache.sling.settings-1.1.0.jar, Jar:OSGI-INF/lib/cq-compat-runmode-0.2.0.jar, Jar:OSGI-INF/lib/commons-c
ollections-3.2.1.jar, Jar:OSGI-INF/lib/squeakysand-jsp-0.4.0.jar, Jar:OSGI-INF/lib/squeakysand-commons-0.4.0.jar]: [org/apache/sling/settings/impl/Run
ModeCommand.class]
To solve this I added below dependancy in pom.xml, as we added in
Dependency
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.shell</artifactId>
<version>1.4.2</version>
<scope>provided</scope>
</dependency>
Under import statement.
<Import-Package>
....
....
org.apache.felix.shell
</Import-Package>
After that, build was successful, but bundle was in resolved state because of
org.apache.felix.shell,version=[1.0,2) -- Cannot be resolved
Any suggestion, why this is causing the problem.
org.apache.felix.shell,version=[1.0,2) -- Cannot be resolved
mean that you are trying to use these felix packages from within AEM. However - there are no OSGi bundles in AEM that exports these packages.
You can download the bundle from maven repo and upload it into the AEM Felix console and use it.
OR you can create it as your parent pom dependency as one of module and wrap along with your project jar and use it.
To veify the availability of any package and dependencies use AEM Dependency finder.
I don't know CQ but I can explain why this happens in general. You had the error during build time because of missing dependency. You correctly solved it by adding the dependency which fixed your build. What happened behind the scenes is your bundle was updated with information that it needs (imports) org.apache.felix.shell,version=[1.0,2) package and that package will be provided by some other bundle at runtime.
Then at runtime the resolver got that information and tried to find a bundle that provides (exports) org.apache.felix.shell,version=[1.0,2) package. It couldn't find one and so the resolution failed and your bundle was left in installed (I believe that's what you meant to write instaed of resolved in your last sentence) state!
To solve that, you need to make sure org.apache.felix.shell,version=[1.0,2) package is available at runtime. I don't know CQ and how to install bundles in it but since you can install your own bundle I assume you can also install org.apache.felix.shell bundle the same way.
The shell jar you have installed is still unresolved as it depends on some jars that might not be present. You need to find the depth of all dependencies and resolve them.

Felix bundles failng to load

I am attempting to run an application on Apache Felix, using the Felix Dependency bundles. The container is, for some reason, not loading my bundles.
I am doing my development using Bndtools in Eclipse. I am using the Amdatu bundles.
The bundles I am concerned about are the bundles that are in my "Run Requirements":
org.apache.felix.dependencymanager
org.apache.felix.dependencymanager.shell
org.apache.felix.dependencymanager.runtime
osgi.core
osgi.cmpn
All of the above bundles are taken from the Amdatu repository.
I have two bundles which I created:
com.test.demo.reader
com.test.demo.listener
And these bundles are built using org.apache.felix.dependencymanager and osgi.core.
When I attempt to run OSGi, I am getting the following failures:
! could not resolve the bundles: [com.test.demo.reader-1.0.0 Unresolved constraint in bundle
com.test.demo.reader [8]: Unable to resolve 8.0: missing requirement
[8.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)(!(version>=4.0.0))),
com.test.demo.listener-1.0.0 Unresolved constraint in bundle com.test.demo.listener [9]:
Unable to resolve 9.0: missing requirement [9.0] osgi.wiring.package;
(&(osgi.wiring.package=com.test.demo.reader)(version>=1.0.0)(!(version>=2.0.0)))
[caused by: Unable to resolve 8.0: missing requirement [8.0] osgi.wiring.package;
(&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)(!(version>=4.0.0)))]]
and
! Failed to start bundle com.test.demo.reader-1.0.0, exception Unresolved constraint in
bundle com.test.demo.reader [8]: Unable to resolve 8.0: missing requirement [8.0]
osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)
(!(version>=4.0.0)))
and more
! Failed to start bundle com.test.demo.listener-1.0.0, exception Unresolved constraint in
bundle com.test.demo.listener [9]: Unable to resolve 9.0:
missing requirement [9.0] osgi.wiring.package; (&(osgi.wiring.package=com.test.demo.reader)
(version>=1.0.0)(!(version>=2.0.0))) [caused by: Unable to resolve 8.0: missing requirement
[8.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)
(!(version>=4.0.0)))]
I think I understand what is happening: apparently the org.apache.dm package being used is a version that is somehow incompatible with my bundles. But that doesn't make any sense, because according to the Felix documentation the org.apache.dm package is in the org.apache.felix.dependencymanager bundle. That bundle is from the Amdatu repository and it is the only version of the bundle I am using with my application! How is the version incompatible with my bundles when theirs is the only version that my bundles know about???
Someone please advise. What is causing this failure an how can I fix it?
The problem was the runtime I was running and what appears to be a bug in the Amdatu plugin.
I would not advise using the Amdatu configuration in your OSGi project. Not in its current form.
The various Felix Dependency bundles that I have been using from Amdatu are apparently intended to run under Felix version 5. Unfortunately, the Amdatu environment (the "Amdatu Configuration" that you can select when you choose a configuration template for your project) does not load Version 5. When you select the "Bundle- Hub configuration", your choice of runtime environments includes all Felix environments from Version 4.0.2 to Version 5.2, as well as several versions of Equinox. When you select the "Amdatu Configuration" you only runtime choices are Felix 4.0.2 and Felix 4.2.0.
I was using 4.2.0 Felix, and as a result the dependency bundles were not working.
The Amdatu environment in its current form is unusable in Bndtools. It apparently supplies the right bundles for Version 5 but does not provide that environment for the user.
I did try manually changing the runtime environment io Version 5.2. This did not work because apparently when you select a template, Bndtools puts together whatever runtimes are associated with the template. Because the Amdatu template does not include Felix version 5, the runtime environment is unavailable.
In order to get my application to run, I had to create a new project that used the "Bundle- Hub" template and manually download the dependency bundles from the Felix website and include them in my buil and runtime environments. Unfortunately, neither Bndtools nor Amdatu provides any way to add the Amdatu bundles to project after a template is selected. This means that instead of using the ready- made bundles from Amdatu, you have to go out to the source sites and manually include them.
I will probably ty and find a way to create a new repository that can be included in projects and contains all the Amdatu bundles, then include that repository in the "Bundle- Hub" template. I will also report the problems with environments (as well as seversl other problems I've seen) to the Amdatu folks.
In the meantime, my application runs smoothly now that I have set up the right runtime environment.
Special thanks to earcam, whose questions in the comment above gave me a clue as to what to start looking at to solve this problem...

Camel Compatibility issues

I am using the following camel packages in my Maven project:
camel-core
camel-jms
camel-jaxb
camel-quartz
camel-bindy
camel-ftp
And when all these are using version 2.8.0 my server starts up fine and the app works ok. But if I update the camel version to anything higher like 2.10.0 then I get the following exception on startup and not sure which of these is causing this issue:
Caused by: org.apache.camel.TypeConverterLoaderException: Failed to load type converters because of: Cannot find any type converter classes from the following packages: [org.apache.camel.component.file.remote]
Any help would be much appreciated?
Maybe another library of your project is using a different version of camel.
You can check the camel dependency tree of your project with this maven command:
mvn dependency:tree -Dverbose -Dincludes=camel-core
In verbose mode, the dependency tree shows dependencies that were omitted for being a duplicate of another, conflicting with another's version and/or scope, and introducing a cycle into the dependency tree.
Here are some reference links:
https://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html
https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html

maven-enforcer-plugin complains about dependencies that I cannot find in pom.xml files

I am encountering a problem with the maven-enforcer-plugin. It is complaining with the following (simplified) output:
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for com.company.project:interfaces:1.0.4 paths to dependency are:
+-com.company.project:product:1.0.14-SNAPSHOT
+-com.company.project:some_part_A:1.0.0
+-com.company.project:interfaces:1.0.4
and
+-com.company.project:product:1.0.14-SNAPSHOT
+-com.company.project:some_part_B:1.0.0
+-com.company.project:some_sub_part_BB:1.1.0
+-com.company.project:interfaces:1.0.4
and
+-com.company.project:product:1.0.14-SNAPSHOT
+-com.company.project:interfaces:1.0.6
The problem is with some_sub_part_BB:1.1.0. According to the plugin, this part has a dependency on version 1.0.4 of the interfaces. But this is not possible: version 1.0.0 of some_sub_part_BB used interfaces version 1.0.3, and version 1.1.0 of some_sub_part_BB went directly to using interfaces version 1.0.6. I do not have any artifacts of some_sub_part_BB that uses version 1.0.4.
I guess I'm looking at some bug of the plugin, but I would like to debug this issue to make sure what is going wrong. Is this an issue anyone has encountered before, or can someone provide me any pointers on how to debug this problem? (I am fairly new to Maven, and aside from checking all the pom.xml files I have no idea where to look further).
Side note: The idea is (was) that the interface version to be used is specified on the project level POM, so that all (sub-) parts agree on which interface to use. However, as you can see, the different parts also specify which interface they use, which I don't think is the correct way of doing this. I haven't figured out how to fix this (yet).
Turns out that this is not a bug: in the pom.xml file, you can overrule versions of artifacts in the section dependencyManagement. In my case, someone enforced version 1.0.4 of the interfaces. The enforcer plugin does not show this; it only became apparent to me after generating the dependency tree with the verbose flag, i.e. mvn dependency:tree -Dverbose.

Beginner starting large OSGi migration - osgi.wiring.package=android.dalvik?

I have a large Java application that's mostly networking and file processing with lots of DB access. There's no UI. We expose a few web services (embedded Netty) and call some external rest web services. The project is built with Ant. It's about 10 different jars plus maybe 30-40 libraries.
My current task is to move the project to the OSGi framework. I am startling slowly.
Following the examples in "OSGi In Action" chapter 6, I have used the BND ant task to put the entire project into one huge jar file. This worked. I am able to run the program using java -jar. Here's my current .bnd file:
-output: bundle/MerchantServicesBundle.jar
-include: manifest/merchantservices.manifest
Bundle-Name: MerchantServices
Bundle-SymbolicName: com.shopping.services.merchant
Bundle-Version: 4.1
Main-Class: com.shopping.merchant.services.netty.MerchantServices
Class-Path: /home/ppantera/repositories/MerchantJava/modules/MerchantServices/conf/
Private-Package: *
I am using Apache Felix 4.0.3. From the Gogo shell I can install the bundle but when I start it I get this:
org.osgi.framework.BundleException: Unresolved constraint in bundle com.shopping.services.merchant [8]: Unable to resolve 8.0: missing requirement [8.0] osgi.wiring.package; (osgi.wiring.package=android.dalvik)
Why does Felix think this is an Android project?
There doesn't seem to be much about this on the 'net. Would you recommend using an older version of Felix so I'm sheltered from the newer OSGi features that could cause me confusion?
I tried adding this to my .bnd file:
Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version>=1.7))"
That didn't help. What am I doing wrong? Any other pointers?
It looks like somehow bnd detected a requirement to an Android package, and added that to the MANIFEST.MF, it could be in your code, but could also be in one of your 3rd party libraries.
Check your manifest to be sure, I guess you'll find something like
Import-Package:android.dalvik.
If that's the case you can test the bundle by manually removing that header and see if that helps. When you've got that clear, you can resolve it for example by making that import optional in bnd.
One of easy solution is:
Go to FuseESB console:
Type the command:
osgi:install mvn:commons-io/commons-io/2.1
Replace 'common's-io' with your your dependency's group id and artifact id (Maven)
e.g my dependency was:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
Cheers

Resources