Unresolved constraint in bundle - maven

When I try to deploy my bundle to OSGi via maven, this shows in installed state. My Project is multimodule, so having two bundles. What I saw in taglib bundle is :
org.apache.felix.shell from org.apache.felix.shell (292)
org.apache.jackrabbit.api,version=[2.3,3) from org.apache.jackrabbit.jackrabbit-api (65)
org.apache.jackrabbit.api.jsr283.security -- Cannot be resolved
org.apache.jackrabbit.api.security,version=[2.3,3) from org.apache.jackrabbit.jackrabbit-api (65)
org.apache.jackrabbit.api.security.principal,version=[2.3,3) from org.apache.jackrabbit.jackrabbit-api (65)
org.apache.jackrabbit.api.security.user,version=[2.3,3) from org.apache.jackrabbit.jackrabbit-api (65)
After checking the logs, I see below:
14.04.2017 17:23:03.330 *ERROR* [FelixDispatchQueue] com.abc.MyPrj-services FrameworkEvent ERROR (org.osgi.framework.BundleException: Unresolved constraint in bundle com.abc.MyPrj-services [290]: Unable to resolve 290.0: missing requirement [290.0] osgi.wiring.package; (osgi.wiring.package=org.apache.jackrabbit.api.jsr283.security)) org.osgi.framework.BundleException: Unresolved constraint in bundle com.abc.MyPrj-services [290]: Unable to resolve 290.0: missing requirement [290.0] osgi.wiring.package; (osgi.wiring.package=org.apache.jackrabbit.api.jsr283.security)
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3896)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1938)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1261)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:298)
at java.lang.Thread.run(Thread.java:745)
I have added below dependency in both modules taglib, services.
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-api</artifactId>
<version>2.5.2</version>
<scope>provided</scope>
</dependency>
Below is the pom of taglib module:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>
com.mypkg.gwms.ra.tags.*;version=${project.version}
</Export-Package>
<Import-Package>
com.adobe.granite.*,
com.day.*,
javax.*,
org.apache.commons.*,
org.apache.sling.*,
org.apache.tika.*,
org.osgi.*,
org.w3c.dom.*,
org.xml.sax.*,
org.slf4j.*,
org.apache.felix.shell.*,
org.apache.jackrabbit.*,
</Import-Package>
<Include-Resource>
META-INF/${project.artifactId}-${project.version}.tld=${project.build.outputDirectory}/META-INF/${project.artifactId}-${project.version}.tld,
{maven-resources},
{maven-dependencies}
</Include-Resource>
<Sling-Bundle-Resources>
/META-INF/tags
</Sling-Bundle-Resources>
</instructions>
</configuration>
</plugin>
Thanks,

I was required to have 2 dependencies of the same API but with the different version. The latest one was using in services module. Other module taglib, was looking for the older version of the same dependency to resolve org.apache.jackrabbit.api.jsr283.security
To solve this, I added below statement in my pom.xml .
<Import-Package>
org.apache.jackrabbit.*;version=1.6.1
</Import-Package>
Only import 1.6.1 version. That's worked.

The error tells you that you also need to install a bundle that provides the package org.apache.jackrabbit.api.jsr283.security.
You can check in the Manifest of a bundle if it exports this package.

You should install a bundle which contains org.apache.jackrabbit.api.jsr283.security package and exports it, to your osgi container.

Related

felix maven-bundle-plugin error (&(osgi.wiring.package=com.a.b.c)(version>=xx.0.0)(!(version>=yy.0.0)

i use Apache Felix to implement osgi bundle and use it as embedded Felix framework to call boundle
here is my maven plugin to build MANIFEST.MF :
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.5.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Bundle-Activator>a.b.c.osgi.activator.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
i build project and then use jar file in embeded felix like this
BundleContext bundleContext = f.getBundleContext();
Bundle bundle = bundleContext.installBundle(
"file:/home/eclipse_workSpace/my-module/target/abc-1.1.0.jar");)
String bName = bundle.getLocation();
bundle.getRegisteredServices();
bundle.getState();
/* Bundle[] bls = bundleContext.getBundles(); */
System.out.println("starting bundle " + bName);
bundle.start();
when i start boundle i got this exception
Exception in thread "main" org.osgi.framework.BundleException: Unable to resolve a.b.c [1](R 1.0): missing requirement [a.b.c [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=com.google.common.base)(version>=21.0.0)(!(version>=22.0.0))) Unresolved requirements: [[a.b.c [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=com.google.common.base)(version>=21.0.0)(!(version>=22.0.0)))]
what should i do to solve this problem?
This error message means that your bundle depends on Google Guava, version 21. Specifically this line:
missing requirement [a.b.c [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=com.google.common.base)(version>=21.0.0)(!(version>=22.0.0)))
... means that your bundle "a.b.c" imports the package com.google.common.base with version greater-than-or-equal to 21 and not-greater-than-or-equal to 22. Since your bundle imports this package, there must be another bundle in your OSGi Framework that exports the package.
The solution is to ensure that Guava 21 is installed into your OSGi Framework.

What Build Module in IntelliJ actually does for maven module

When I run
mvn clean install
for my maven module then it compiles fine. No issues.
But when I open my pom.xml file in IntelliJ and I choose to Build -> Build module then I get following issues:
Information:javac 1.8.0_144 was used to compile java sources
Information:Module "mymodule" was fully rebuilt due to project configuration/dependencies changes
Information:09.10.2017 21:16 - Compilation completed with 3 errors and 3 warnings in 23s 991ms
C:\somepath\mymodule\pom.xml
Error:Error:osgi: [mymodule] Exception: java.lang.ClassNotFoundException: org.apache.sling.bnd.models.ModelsScannerPlugin not found, parent: java.net.URLClassLoader#29453f44 urls:[] exception:java.lang.ClassNotFoundException: org.apache.sling.bnd.models.ModelsScannerPlugin
Error:Error:osgi: [mymodule] Failed to load plugin org.apache.sling.bnd.models.ModelsScannerPlugin;generatePackagesHeader=true, error: java.lang.ClassNotFoundException: org.apache.sling.bnd.models.ModelsScannerPlugin not found, parent: java.net.URLClassLoader#29453f44 urls:[] exception:java.lang.ClassNotFoundException: org.apache.sling.bnd.models.ModelsScannerPlugin
Error:Error:osgi: [mymodule] Cannot load the plugin org.apache.sling.bnd.models.ModelsScannerPlugin
This is a module with AEM code and it uses maven-sling-plugin. It works fine for other developers in the project. Because it's working when executed directly from maven I'm trying to understand what IntelliJ does in the background. But actually, my problem is those compilation issues.
From what I've found IntelliJ does not call maven when Build is done. Any ideas how can I find differences between running from IntelliJ and directly from Maven?
What happens here is that the ModelScanner plugin can't be found using the current ClassLoader. The reason for this can be that you are using IntelliJ IDEA Ultimate which comes with a OSGI plugin already pre-installed called 'Osmorc'. If this OSGI plugin is active it will determine the classloader to be used for building OSGI related projects.
So simply de-activating this Osmorc plugin in IntelliJ should allow your build to revert to the classloader from the ModelScannerPlugin mentioned in the configuration of your the maven-bundle-plugin in your projects POM.xml file which should solve the problem.
If this still results in a similar Maven build error, then make sure to add a Maven dependency 'org.apache.sling.bnd.model' to your maven-bundle-plugin in your POM.xml file.
<!-- Apache Felix Bundle Plugin -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<inherited>true</inherited>
<extensions>true</extensions>
<executions>
<!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
<execution>
<id>scr-metadata</id>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<supportIncrementalBuild>true</supportIncrementalBuild>
</configuration>
</execution>
</executions>
<configuration>
<exportScr>true</exportScr>
<instructions>
<!-- Enable processing of OSGI DS component annotations -->
<_dsannotations>*</_dsannotations>
<!-- Enable processing of OSGI metatype annotations -->
<_metatypeannotations>*</_metatypeannotations>
<_plugin>org.apache.sling.bnd.models.ModelsScannerPlugin;generatePackagesHeader=true</_plugin>
</instructions>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.bnd.models</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
could you please check your core pom file. it should contain a plugin section like this:
<plugin> <!-- Enable registration of Sling Models classes via bnd plugin --> org.apache.sling.bnd.models.ModelsScannerPlugin, <!-- Allow the processing of SCR annotations via a bnd plugin --> org.apache.felix.scrplugin.bnd.SCRDescriptorBndPlugin;destdir=${project.build.outputDirectory} </plugin>
but if you created a project using aem archetype the tag looks like' <_plugin>

ClassCastException with OSGI bundle

I am working on OSGi bundle, which uses javax.ws.rs-api (2.0.1). Karaf is already having jsr311-api (1.1.1) loaded as bundle. When I try to load my OSGi bundle, I see the following exception. Is there a way we can ignore the previously loaded bundle?
The activate method has thrown an exception
java.lang.LinkageError: ClassCastException: attempting to castbundle://137.0:1/javax/ws/rs/ext/RuntimeDelegate.class to bundle://177.0:1/javax/ws/rs/ext/RuntimeDelegate.class
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:146)[137:javax.ws.rs.jsr311-api:1.1.1]
at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:120)[137:javax.ws.rs.jsr311-api:1.1.1]
at javax.ws.rs.core.UriBuilder.newInstance(UriBuilder.java:95)[137:javax.ws.rs.jsr311-api:1.1.1]
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)[137:javax.ws.rs.jsr311-api:1.1.1]
Your bundle must import only the packages you need versions.
You have to create META-INF\MANIFEST.MF with Import-Package header, which will contain the list of packages required only versions.
Import-Package: javax.ws.rs.ext,version="2.0.1"
List all the packages that cause the conflict.
I think here they are:
javax.ws.rs,version="2.0.1"
javax.ws.rs.client,version="2.0.1"
javax.ws.rs.container,version="2.0.1"
javax.ws.rs.core,version="2.0.1"
javax.ws.rs.ext,version="2.0.1"
You can specify a range of versions : [2.0.1, 3) and so on.
Real example:
Import-Package: org.osgi.service.blueprint; version="[1.0.0, 2.0.0)"
You can use maven-bundle-plugin to create requered MANIFEST.MF:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Description>${project.description}</Bundle-Description>
<Import-Package>
javax.ws.rs;version=2.0.1,
javax.ws.rs.client;version=2.0.1,
javax.ws.rs.container;version=2.0.1,
javax.ws.rs.core;version=2.0.1,
javax.ws.rs.ext;version=2.0.1,
*,
org.apache.camel.osgi
</Import-Package>
<Export-Package>
your.package
</Export-Package>
</instructions>
</configuration>
</plugin>
Don't forget to install bundle version 2.0.1

OSGI bundle is not getting started in Apache Servicemix

I am developing http client application as a OSGI bundle project, i have used apache maven to create project folder structure used below command.
mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-blueprint-archetype -DarchetypeVersion=2.3.7 -DgroupId=com.techiyhub -DartifactId=integration.sms -Dversion=1.0-SNAPSHOT -Dpackage=com.techiyhub.integration.sms
The above command created project folder structure, as i am using httpclient based application. i have added dependencies in pom.xml as below.
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>
<groupId>com.techiyhub</groupId>
<artifactId>integration.sms</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>integration.sms Blueprint Bundle</name>
<description>integration.sms OSGi blueprint bundle project.</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>
com.techiyhub.integration.sms*;version=${project.version}
</Export-Package>
<Import-Package>
*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
I executed below command,
mvn install
it created desired jar file in local maven repository.
Problem started here. i tried to deploy the bundle in apache servicemix it has installed the bundle but while starting bundle it gave an error
i have executed below commands in servicemix shell
osgi:install mvn:com.techiyhub/integration.sms/1.0-SNAPSHOT
it got installed with bundle id, then i executed below command
osgi:start 302
It gave below error
Error executing command: Error starting bundles:
Unable to start bundle 302: Unresolved constraint in bundle integration.sms [302]: Unable to resolve 302.0: miss
ing requirement [302.0] osgi.wiring.package; (osgi.wiring.package=org.apache.http)
Full error stack trace as below
2015-10-26 14:33:12,551 | ERROR | l Console Thread | Console | 22 - org.apache.karaf.shell.cons
ole - 2.4.3 | Exception caught while executing command
org.apache.karaf.shell.console.MultiException: Error starting bundles:
Unable to start bundle 302: Unresolved constraint in bundle integration.sms [302]: Unable to resolve 302.0: miss
ing requirement [302.0] osgi.wiring.package; (osgi.wiring.package=org.apache.http)
at org.apache.karaf.shell.console.MultiException.throwIf(MultiException.java:91)
at org.apache.karaf.shell.osgi.StartBundle.doExecute(StartBundle.java:43)
at org.apache.karaf.shell.osgi.BundlesCommand.doExecute(BundlesCommand.java:37)
at org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:38)
at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(AbstractCommand.java:35)
at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_80]
at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_80]
at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:54)[16:org.apache.aries.proxy.impl:1.0.4]
at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:119)[16:org.apache.aries.proxy.impl:1.0.4]
at org.apache.karaf.shell.console.commands.$BlueprintCommand22803378.execute(Unknown Source)[22:org.apache.karaf
.shell.console:2.4.3]
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)[22:org.apache.karaf.shell.console:2.
4.3]
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)[22:org.apache.karaf.shell.console:2.4.3]
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)[22:org.apache.karaf.shell.console:2.
4.3]
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[22:org.apache.karaf.shell.console:2.4.3]
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)[22:org.apache.karaf.shell.console:2.4.3]
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)[22:org.apache.karaf.shell.console:2.4.3]
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:92)[22:org.apache.karaf.shel
l.console:2.4.3]
at org.apache.karaf.shell.console.jline.Console.run(Console.java:195)[22:org.apache.karaf.shell.console:2.4.3]
at org.apache.karaf.shell.console.jline.DelayedStarted.run(DelayedStarted.java:79)[22:org.apache.karaf.shell.con
sole:2.4.3]
Caused by: java.lang.Exception: Unable to start bundle 302: Unresolved constraint in bundle integration.sms [302]: Unabl
e to resolve 302.0: missing requirement [302.0] osgi.wiring.package; (osgi.wiring.package=org.apache.http)
at org.apache.karaf.shell.osgi.StartBundle.doExecute(StartBundle.java:39)
... 18 more
Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle integration.sms [302]: Unable to resolve
302.0: missing requirement [302.0] osgi.wiring.package; (osgi.wiring.package=org.apache.http)
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4002)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2045)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:963)
at org.apache.karaf.shell.osgi.StartBundle.doExecute(StartBundle.java:37)
... 18 more
Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle : Unable to resolve: missing requirement [302.0] osgi.wiring.package;(osgi.wiring.package=org.apache.http)
Please help me out on this.
When you create a bundle the maven bundle plugin scans the class files of your project for all used packages. It creates Import-Package statements for these in the Manifest.
Then at runtime you have to make sure you also install all necessary libraries you need to run your bundle. The error message helps you in finding the correct bundles to install. So in your case you have to install a bundle that exports the package org.apache.http.
In your case these are:
mvn:org.apache.httpcomponents/httpcore-osgi/4.3.3
mvn:org.apache.httpcomponents/httpclient-osgi/4.3.6

service provider and OSGI issue

I have written an osgi bundle, where i have dependency for a jar(bsf-all.jar), which contains service provider as follows (under META_inf/services/);
bsh.engine.BshScriptEngineFactory
com.sun.script.freemarker.FreeMarkerScriptEngineFactory
com.sun.script.groovy.GroovyScriptEngineFactory
com.sun.script.jacl.JaclScriptEngineFactory
com.sun.script.jaskell.JaskellScriptEngineFactory
com.sun.script.java.JavaScriptEngineFactory
com.sun.phobos.script.javascript.RhinoScriptEngineFactory
com.sun.phobos.script.javascript.EmbeddedRhinoScriptEngineFactory
com.sun.script.jawk.JawkScriptEngineFactory
com.sun.script.jelly.JellyScriptEngineFactory
com.sun.script.jep.JepScriptEngineFactory
com.sun.script.jexl.JexlScriptEngineFactory
com.sun.script.jruby.JRubyScriptEngineFactory
com.sun.script.judo.JudoScriptEngineFactory
com.sun.script.juel.JuelScriptEngineFactory
com.sun.script.jython.JythonScriptEngineFactory
com.sun.script.ognl.OgnlScriptEngineFactory
org.pnuts.scriptapi.PnutsScriptEngineFactory
com.sun.script.scheme.SchemeScriptEngineFactory
com.sun.script.velocity.VelocityScriptEngineFactory
com.sun.script.xpath.XPathScriptEngineFactory
com.sun.script.xslt.XSLTScriptEngineFactory
When i check my bundle state via OSGI console , it is Active and there is no any dependency issue..
But when i try to use it(means after the server up and running)
server throws "Class not found" issue ;
java.lang.ClassNotFoundException: com.sun.phobos.script.javascript.RhinoScriptEngineFactory
This particular class is in my dependency jar(bsf-all.jar) and that class is exposed via the service provider..
I suspect there is a class loading issue with OSGi and java service provider..
My pom.xml is as follows;
<dependencies>
<dependency>
<groupId>org.apache.bsf</groupId>
<artifactId>bsf-all</artifactId>
<version>${bsf.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
<version>1.6R7</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Export-Package>
org.apache.bsf.*,
org.mozilla.javascript.*,
org.pnuts.scriptapi.*,
com.sun.script.*,
com.sun.phobos.script.*,
bsh.engine.*,
javax.script.*,
</Export-Package>
<Import-Package>
com.sun.*
</Import-Package>
<DynamicImport-Package>*</DynamicImport-Package>
<Embed-Dependency>js;scope=compile|runtime;inline=false;</Embed-Dependency>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
I'm using Equinox OSGi implementation..How can i edit my pom to overcome above issue?
I feel that there are too many fundamental errors in this POM to begin speculating about the cause of the CNFE. Your <Export-Package> statement is of most concern. Why are you repackaging and exporting the whole of BSF, Rhino, Phobos and even parts of the JDK inside your bundle??
As I implied in my answer to your earlier question: you are getting bogged down in low-level details without, I think, having a good understanding of what you are trying to achieve at the high level. Therefore even if somebody posts an answer that gets you past this particular issue, you will still not have a working architecture.
Please step back and describe at a high level what you are trying to achieve and why. Then we can offer a solution based on good OSGi practices.

Resources