I made a service in OSGi that uses Spark to provide a rest endpoint.
I get the following error:
Error
Error executing command: Error executing command on bundles:
Error starting bundle 66: Unable to resolve OSGiConsumerProducer.ProducerConsumer.helloendpoint [66](R 66.0): missing requirement [OSGiConsumerProducer.ProducerConsumer.helloendpoint [66](R 66.0)] osgi.wiring.package; (osgi.wiring.package=spark.Spark.get) Unresolved requirements: [[OSGiConsumerProducer.ProducerConsumer.helloendpoint [66](R 66.0)] osgi.wiring.package; (osgi.wiring.package=spark.Spark.get)]
I have defined by POM to compile as so:
<instructions>
<Bundle-SymbolicName>${parent.groupId}.${parent.artifactId}.helloendpoint</Bundle-SymbolicName>
<Bundle-Activator>com.osgi.endpoint.EndpointActivator</Bundle-Activator>
<Import-Package>
spark.Spark.get
</Import-Package>
<Export-Package>
com.osgi.endpoint.HelloEndpointAPI
</Export-Package>
<Bundle-ManifestVersion>2</Bundle-ManifestVersion>
</instructions>
I'm under the assumption I only need to export the interface my impl class uses, then import the Spark package, since I'm using it inside this module?
Potential Problem:
Do I need to install Spark into Karaf?
Are you sure that spark.Spark.get is the name of a Java package?? It sounds more like a method name.
My advice is to remove the Import-Package section of these instructions completely. The tool is more than capable of working out which packages your bundle needs to import.
Related
BndTools, How to add a non-OSGi JAR? I wanted to add jcraft Libraries into my osgi project. Using plain JAR breaks the whole project. Missing requirement wiring package
ERROR: Bundle com.herle.iiot.application.installation [6] Error starting file:/D:/HERLE/Data/iot-sdk/FelixLauncher/bundle/com.herle.iiot.application.installation-1.5.0.jar
(org.osgi.framework.BundleException: Unable to resolve com.herle.iiot.application.installation [6](R 6.0): missing requirement [com.herle.iiot.application.installation [6](R 6.0)] osgi.w
iring.package; (osgi.wiring.package=com.jcraft.jzlib) Unresolved requirements: [[com.herle.iiot.application.installation [6](R 6.0)] osgi.wiring.package; (osgi.wiring.package=com.jcraft.jzlib)]
)
org.osgi.framework.BundleException: Unable to resolve com.herle.iiot.application.installation [6](R 6.0): missing requirement [com.herle.iiot.application.installation [6](R 6.0)] osgi.wi
ring.package; (osgi.wiring.package=com.jcraft.jzlib) Unresolved requirements: [[com.herle.iiot.application.installation [6](R 6.0)] osgi.wiring.package; (osgi.wiring.package=com.jcraft.jzlib)]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
at java.lang.Thread.run(Unknown Source)
[Device Manager] info: Passive start
Watched path D:\HERLE\Data\iot-sdk\FelixLauncher\fileinstall key sun.nio.fs.WindowsWatchService$WindowsWatchKey#ae7c53
{felix.fileinstall.poll (ms) = 2000, felix.fileinstall.dir = D:\HERLE\Data\iot-sdk\FelixLauncher\.\fileinstall, felix.fileinstall.log.level = 4, felix.fileinstall.bundles.new.start = tru
e, felix.fileinstall.tmpdir = .\tmp, felix.fileinstall.filter = null, felix.fileinstall.start.level = 0}
Please let me know how can one do this using bnd.bnd config file?
Main thing to consider is configuration. If you are using external library or jar then you need to mention it as private package.
please find my sample bnd.bnd file.
Bundle-Name: ${project.artifactId}
Bundle-SymbolicName: ${project.artifactId}
Bundle-Description: Template-Bundle for developing an application
Bundle-Category: Application
Bundle-Copyright: 2017 (c) Herleraja#gmail.com
-dsannotations: *
-metatypeannotations: *
Private-Package: \
com.jcraft,\
com.jcraft.jsch,\
com.jcraft.jsch.jce,\
com.jcraft.jsch.jcraft,\
com.jcraft.jsch.jgss,\
com.jcraft.jzlib
I suggest you to use BndTools to edit the bnd.bnd file.
you can install BndTools plugin to eclipse from BndTool Installation.
Select the packages that you need.
Note: Since it automatically does not install all the dependencies you need to add if any extra jars required. i.e I wanted to use jsch, which had a dependency on jzlib. So I added these two entries in pom.xml file.
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
<version>1.1.3</version>
</dependency>
Hope this helps some! Please vote so that i can write more solution.
I have maven project where i am adding the dependencies which are not resolvable as below.
My servlet is as follows:
LocaleUtil is getting resolve but its sub packages are throwing error when including.
I have tried invalidate cache and restart. But this didn't work for me.
Thanks,
The packages you are trying to import are internal, non-exported packages of the bundle com.adobe.granite.i18n. In fact, that bundle only exports the following packages:
Export-Package
com.adobe.granite.i18n {version=1.0, imported-as=[1.0.0,1.1)}
com.day.cq.i18n {version=5.4.0}
You should not attempt to use private packages of a library. Limit yourself to using only the exported API.
My question is similar to this one but I am using the Maven bundle plugin to achieve the same end result.
I am building a bundle that contains a persistence.xml file and I have found that the maven-bundle-plugin automatically generates the following headers in the manifest:
Require-Capability:osgi.service;effective:=active;objectClass=javax.persistence.spi.PersistenceProvider;javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
Require-Capability: osgi.extender;osgi.extender=aries.jpa,
Require-Capability: osgi.service;effective:=active;objectClass=javax.sql.DataSource;filter:="(osgi.jndi.service.name=jdbc/test)"
This in itself is not a problem however I am using Karaf and I want to deploy this and other bundles and Karaf features in one single feature of my own. When I do this it fails because the OSGi is unable to fulfil the capability osgi.service;effective:=active;objectClass=javax.persistence.spi.PersistenceProvider;javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl even though I specify the openjpa feature to be installed at the same time. I have discovered that I can get around this issue by changing effective:=active to resolution:=optional
To build my bundle I've tried the following Maven plugin configuration:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>com.example
</Export-Package>
<Include-Resource>
META-INF/persistence.xml=${project.build.directory}/classes/META-INF/persistence.xml,
{maven-resources}
</Include-Resource>
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
<Require-Capability>
osgi.service;resolution:=optional;objectClass=javax.persistence.spi.PersistenceProvider;javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
osgi.extender;resolution:=optional;osgi.extender=aries.jpa,
osgi.service;resolution:=optional;objectClass=javax.sql.DataSource;filter:="(osgi.jndi.service.name=jdbc/test)"
</Require-Capability>
</instructions>
</configuration>
</plugin>
However I get the same issue as in the linked question above i.e. duplicated requirements in the manifest.
I also see from a link on the above question that a change was made to bnd (bnd issue #1364) but this appears to only work for annotations? Is there a way to configure the Maven plugin to prevent duplicated requirements?
Update #1
My example code is available here at GitHub (karaf_features branch):
https://github.com/jtkb/jpatest/tree/feature/karaf_features
It consists of 3 modules but only 2 are of interest for this issue, simple and simple-datasource
simple is the 'persistence unit' and contains the persistence.xml. It is also the bundle in which the 'awkward' (yet real requirements) <Require-Capability> headers are generated.
simple-datasource provides the datasource to the persistence unit and contains a Karaf feature to install simple, simple-datasource bundles and all the required 3rd party bundles (via Karaf features). The feature XML contains:
<feature name="simple-datasource" description="simple-datasource" version="1.0.0.SNAPSHOT">
<feature version="4.1.1">jdbc</feature>
<feature version="2.6.0">jpa</feature>
<feature version="2.4.1">openjpa</feature>
<feature version="1.0.1">pax-jdbc-mariadb</feature>
<bundle>mvn:com.javatechnics.jpa/simple-datasource/1.0.0-SNAPSHOT</bundle>
<bundle>mvn:com.javatechnics.jpa/simple/1.0.0-SNAPSHOT</bundle>
</feature>
So installing my feature in Karaf I get this error:
Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=simple-datasource; type=karaf.feature; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; filter:="(&(osgi.identity=simple-datasource)(type=karaf.feature)(version>=1.0.0.SNAPSHOT)(version<=1.0.0.SNAPSHOT))"
[caused by: Unable to resolve simple-datasource/1.0.0.SNAPSHOT: missing requirement [simple-datasource/1.0.0.SNAPSHOT] osgi.identity; osgi.identity=com.javatechnics.jpa.simple; type=osgi.bundle; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; resolution:=mandatory
[caused by: Unable to resolve com.javatechnics.jpa.simple/1.0.0.SNAPSHOT: missing requirement [com.javatechnics.jpa.simple/1.0.0.SNAPSHOT] osgi.service; objectClass=javax.persistence.spi.PersistenceProvider; javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl; effective:=active]]
The error to me almost feels like a circular reference issue but I cannot see how.
Inspecting the header of the simple bundle:
simple (59)
-----------
Bnd-LastModified = 1513115007378
Build-Jdk = 1.8.0_144
Built-By = kerry
Created-By = Apache Maven Bundle Plugin
Manifest-Version = 1.0
Meta-Persistence = META-INF/persistence.xml
Tool = Bnd-3.2.0.201605172007
Bundle-Blueprint = OSGI-INF/blueprint/blueprint.xml
Bundle-ManifestVersion = 2
Bundle-Name = simple
Bundle-SymbolicName = com.javatechnics.jpa.simple
Bundle-Version = 1.0.0.SNAPSHOT
Export-Service =
com.javatechnics.jpa.dao.BookServiceDao;ServiceManager=Blueprint;name=
BookServiceDao
Provide-Capability =
osgi.service;effective:=active;objectClass=javax.persistence.EntityManagerFactory;osgi.unit.name=test,
osgi.service;effective:=active;objectClass=org.apache.aries.jpa.template.JpaTemplate;osgi.unit.name=test,
osgi.service;effective:=active;objectClass=javax.persistence.EntityManager;osgi.unit.name=test,
osgi.service;effective:=active;objectClass=org.apache.aries.jpa.supplier.EmSupplier;osgi.unit.name=test
Require-Capability =
osgi.service;effective:=active;javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl;objectClass=javax.persistence.spi.PersistenceProvider,
osgi.extender;osgi.extender=aries.jpa,
osgi.service;effective:=active;filter:=(osgi.jndi.service.name=jdbc/test);objectClass=javax.sql.DataSource,
osgi.ee;filter:=(&(osgi.ee=JavaSE)(version=1.5))
Export-Package =
com.javatechnics.jpa;uses:="com.javatechnics.jpa.dao,javax.persistence";version=1.0.0,
com.javatechnics.jpa.dao;uses:=com.javatechnics.jpa;version=1.0.0
Import-Package =
com.javatechnics.jpa,
com.javatechnics.jpa.dao,
javax.persistence;version="[1.1,2)",
org.osgi.service.blueprint;version="[1.0.0,2.0.0)"
If you know that a bundle, let’s call it xyz, provides the PersistenceProvider service then you can write one additional bundle that simply does this:
Require-Bundle: xyz; bundle-version="[...)"
Provide-Capability: osgi.service;
objectClass=javax.persistence.spi.PersistenceProvider;
javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl;
effective:=active
This essentially augments bundle xyz with a capability that will resolve the requirement in your bundle, at the cost of adding an otherwise useless bundle.
This is still something of a workaround but is better than removing a real requirement from a bundle.
I am trying to add bouncy castle as a service provider to my java product running on apache karaf.
When I am trying to start the bundle which imports bouncy castle I get an error message
java.lang.Exception: Could not start bundle mvn:com.xxx.yyy.zzz/docsservice/1.0.0-SNAPSHOT/war in feature(s) server-docs-1.0.0-SNAPSHOT: Unresolved constraint in bundle docs [245]: Unable to resolve 245.0: missing requirement [245.0] osgi.wiring.package; (&(osgi.wiring.package=org.bouncycastle.jce.provider)(version>=1.51.0))
at org.apache.karaf.features.internal.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:472)
In the pom file I imported the package org.bouncycastle.jce.provider and I added bouncycastle as a dependency.
Also, i made all the changes described on this page,
http://karaf.apache.org/manual/latest/users-guide/security.html, see below
I put provider jar in lib/ext
I Modified the etc/config.properties configuration file to add the following property
org.apache.karaf.security.providers = xxx,yyy
org.apache.karaf.security.providers = org.bouncycastle.jce.provider.BouncyCastleProvider
I provided access to the classes from those providers from the system bundle so that all bundles can access those. I did this by modifying the org.osgi.framework.bootdelegation property in the same configuration file:
org.osgi.framework.bootdelegation = ...,org.bouncycastle*
On some forum I found another suggestion so I modified
*org.osgi.framework.system.packages.extra = * in the config.properties as well and I added here packages exported from bouncycastle
Nonetheless I wasn't able to load the bundle successfully. I looked at all the bundles loaded by karaf and none of them was exporting bouncy castle package.
What am I missing here? How can I make the bundles to start?
By adding the package to the boot delegation you made it available like java.* packages. For these you do not need an Import-Package. So one way would be to remove the Import-Package for it in your bundle. You should rather explore though if you can work without boot delegation.
Please try to remove the boot delegation and add the package to
org.osgi.framework.system.packages.extra = org.bouncycastle.jce.provider
This adds the package to the packages the system bundle exports. It should then be wired to your bundle.
I am trying to publish some web services (using EndpointImpl.publish()) but I am gettings this error:
Provider org.apache.cxf.jaxws.spi.ProviderImpl not found
the cxf-bundle is installed:
[ 79] [Active ] [Created ] [ 50] Apache CXF Bundle Jar (2.4.3.fuse-01-02)
an extract of the osgi:headers shows the imported package
Import-Package =
javax.jws,
javax.persistence;version="[1.1,2)",
javax.servlet;version="[2.5,3)",
javax.xml.bind,
javax.xml.bind.annotation,
javax.xml.bind.annotation.adapters,
javax.xml.datatype,
javax.xml.namespace,
javax.xml.parsers,
javax.xml.transform,
javax.xml.transform.stream,
javax.xml.validation,
javax.xml.ws;version="[2.2,3)",
javax.xml.ws.soap;version="[2.2,3)",
javax.xml.ws.wsaddressing;version="[2.2,3)",
org.apache.commons.lang;version="[2.5,3)",
org.apache.commons.logging;version="[1.1,2)",
org.apache.cxf.jaxws;version="[2.4,3)",
org.apache.cxf.jaxws.spi;version="[2.4,3)", <--- imported
org.apache.cxf.ws.addressing;version="[2.4,3)",
org.apache.felix.gogo.commands;version="[0.10,1)",
org.apache.openjpa.enhance;version="[2.2,3)",
org.apache.openjpa.util;version="[2.2,3)",
org.osgi.framework;version="[1.5,2)",
org.osgi.service.blueprint;version="[1.0.0,2.0.0)",
org.springframework.beans.factory.xml;version="[3.0,4)",
org.springframework.context;version="[3.0,4)",
org.springframework.context.support;version="[3.0,4)",
org.w3c.dom,
org.xml.sax
Require-Bundle =
org.apache.cxf.bundle
I am not sure what else I need to do.
in case it is important. the container is a karaf 2.2.7
to address pooh's answer:
1- cxf-bundle is exporting this package: org.apache.cxf.jaxws.spi;version="2.4.3.fuse-01-02"
2- bundle was started. the error was during runtime.
3- the manifest was created using maven-bundle-plugin which should create the entire list
4- the error happen while creating a webservice endpoint:
TopologyIFPortType impl = new TopologyWS();
String addressTopology = "http://localhost:" + port
+ "/nsp/webservice/topology";
topologyEndpoint = (EndpointImpl) Endpoint.create(impl);
topologyEndpoint.getFeatures().add(new WSAddressingFeature());
topologyEndpoint.publish(addressTopology);
the complete trace:
javax.xml.ws.spi.FactoryFinder$ConfigurationError: Provider org.apache.cxf.jaxws.spi.ProviderImpl not found
at javax.xml.ws.spi.FactoryFinder$2.run(FactoryFinder.java:130)
at javax.xml.ws.spi.FactoryFinder.doPrivileged(FactoryFinder.java:220)
at javax.xml.ws.spi.FactoryFinder.newInstance(FactoryFinder.java:124)
at javax.xml.ws.spi.FactoryFinder.access$200(FactoryFinder.java:44)
at javax.xml.ws.spi.FactoryFinder$3.run(FactoryFinder.java:211)
at javax.xml.ws.spi.FactoryFinder.doPrivileged(FactoryFinder.java:220)
at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:160)
at javax.xml.ws.spi.Provider.provider(Provider.java:43)
at javax.xml.ws.Endpoint.create(Endpoint.java:41)
at javax.xml.ws.Endpoint.create(Endpoint.java:37)
at org.opennaas.extensions.idb.webservice.WebServiceHolder.startTopology(WebserviceControl.java:78)
at org.opennaas.extensions.idb.webservice.WebServiceHolder.start(WebserviceControl.java:60)
at org.opennaas.extensions.idb.webservice.WebserviceControl.startWebservices(WebserviceControl.java:32)
at org.opennaas.extensions.idb.shell.StartWebservices.doExecute(StartWebservices.java:16)
at org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:38)
at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(AbstractCommand.java:35)
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:474)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:400)
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)
at org.apache.karaf.shell.console.jline.Console.run(Console.java:240)
at java.lang.Thread.run(Thread.java:679)
The version of CXF you use seem to be quite old. You should try with the current release 2.6.1. In 2.6 a lot of OSGi improvements were introduced.
You can install it using:
features:chooseurl cxf 2.6.1
features:install cxf
Don't worry, OSGi gives you full access to the information which bundle uses which package etc. You only have to know how to ask the system to give you the info you need for debugging the problem.
Unfortunately I am not familiar with karaf console commands, I am working more with ProSyst's mBeddedServer OSGi framework, but since all this is standard in OSGi, I can tell you what to look for and you can find the needed commands in karaf.
So, check the following:
1. Is Apache cxf bundle successfully installed? Is it in the "active" state?
(from your posting it seems that it is)
What is the version of the org.apache.cxf.jaxws.spi package that it exports?
This is different from the cxf bundle version!!!
In order to see the package version, look inside the manifest of the cxf bundle, and look for the Export-package header.
Is your bundle installed and started successfully? Is it in the active state?
If the error "Provider not found" appears during starting of your bundle, then your dependencies are not matching the provided packages from the cxf bundle, see point 2.
If, however, the error appears during runtime, it could have several causes:
You haven't imported all needed packages in your manifest. Try using analysis tools which can generate the manifest for you based on your source code.
or:
The code which does the publishing is located e.g. on the system classpath and uses the system classloader, which in OSGI due to modularity and security reasons doesn't have access to the bundle classloaders.
Check what is provided by the system classpath instead of as OSGi bundles. Anything there which uses Class.forName or other reflection methods won't work in the modular OSGi framework.
There are also other possibilites, but you'll need to provide more info. Was there an exception stack trace? What classes are involved in this piece of code and where on the classpath are they located? etc.