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.
Related
I am developing a plugin for BitBucket Server. Today, the Maven instance started throwing the following error after I changed the scope of one dependency:
[ERROR] Manifest com.my-plugin:integrationPlugin:atlassian-plugin:0.1-DEV : The default package '.' is not permitted by the Import-Package syntax.
This can be caused by compile errors in Eclipse because Eclipse creates
valid class files regardless of compile errors.
The following package(s) import from the default package null
[ERROR] Error(s) found in manifest configuration
After I reverted the change, the error did not go away.
I have tried solutions described in other StackOverflow posts, but they did not help me, since:
I am not using Eclipse
I have all packages declared in all my class files
The Bundle tool has this error fixed already
The manifest I got from the Maven debugging output is:
[DEBUG] Final Manifest:
#-----------------------------------------------------------------------
Manifest-Version: 1.0
Atlassian-Build-Date: 2019-04-04T11:44:27+0000
Atlassian-Plugin-Key: com.my-plugin.integrationPlugin
Bnd-LastModified: 1554378274635
Build-Jdk: 1.8.0_191
Built-By: egta136
Bundle-ClassPath: .,META-INF/lib/commons-logging-1.2.jar,META-INF/lib/pd
fbox-2.0.14.jar,META-INF/lib/fontbox-2.0.14.jar,META-INF/lib/ij-1.52n.j
ar
Bundle-Description: This is the com.my-plugin:integrationPlugin plu
gin for Atlassian Bitbucket Server.
Bundle-DocURL: https://example.com
Bundle-ManifestVersion: 2
Bundle-Name: integrationPlugin
Bundle-SymbolicName: com.my-plugin.integrationPlugin
Bundle-Vendor: Example
Bundle-Version: 0.1.0.DEV
Created-By: Apache Maven Bundle Plugin
Export-Package: com.my-plugin.integrationPlugin.api;version="0.1.0"
Import-Package:
com.apple.eawt;version=0;resolution:=optional,
com.atlassian.bitbucket.auth;version=0;resolution:=optional,
com.atlassian.bitbucket.commit;version=0;resolution:=optional,
com.atlassian.bitbucket.project;version=0;resolution:=optional,
com.atlassian.bitbucket.user;version=0;resolution:=optional,
com.atlassian.plugin.spring.scanner.annotation.export;version=0;resolut
ion:=optional,
com.atlassian.plugin.spring.scanner.annotation.imports;version=0;resolu
tion:=optional,
com.atlassian.sal.api;version=0;resolution:=optional,
com.atlassian.sal.api.pluginsettings;version=0;resolution:=optional,
com.atlassian.soy.renderer;version=0;resolution:=optional,
com.dizainsync.ddm.integrationPlugin.api;version=0;resolution:=optional
,
com.fasterxml.jackson.databind;version=0;resolution:=optional,
com.google.common.collect;version=0;resolution:=optional,
javax.crypto;version=0;resolution:=optional,
javax.crypto.spec;version=0;resolution:=optional,
javax.imageio;version=0;resolution:=optional,
javax.imageio.metadata;version=0;resolution:=optional,
javax.imageio.plugins.jpeg;version=0;resolution:=optional,
javax.imageio.stream;version=0;resolution:=optional,
javax.inject;version=0;resolution:=optional,
javax.script;version=0;resolution:=optional,
javax.servlet;version=0;resolution:=optional,
javax.servlet.http;version=0;resolution:=optional,
javax.swing;version=0;resolution:=optional,
javax.swing.event;version=0;resolution:=optional,
javax.swing.table;version=0;resolution:=optional,
javax.swing.text;version=0;resolution:=optional,
javax.swing.text.html;version=0;resolution:=optional,
javax.swing.tree;version=0;resolution:=optional,
javax.tools;version=0;resolution:=optional,
javax.xml.namespace;version=0;resolution:=optional,
javax.xml.parsers;version=0;resolution:=optional,
javax.xml.xpath;version=0;resolution:=optional,
org.apache.avalon.framework.logger;version=0;resolution:=optional,
org.apache.commons.fileupload;version=0;resolution:=optional,
org.apache.commons.fileupload.disk;version=0;resolution:=optional,
org.apache.commons.fileupload.servlet;version=0;resolution:=optional,
org.apache.commons.io;version=0;resolution:=optional,
org.apache.commons.lang3;version=0;resolution:=optional,
org.apache.log;version=0;resolution:=optional,
org.apache.log4j;version=0;resolution:=optional,
org.bouncycastle.asn1;version=0;resolution:=optional,
org.bouncycastle.asn1.cms;version=0;resolution:=optional,
org.bouncycastle.asn1.pkcs;version=0;resolution:=optional,
org.bouncycastle.asn1.x500;version=0;resolution:=optional,
org.bouncycastle.asn1.x509;version=0;resolution:=optional,
org.bouncycastle.cert;version=0;resolution:=optional,
org.bouncycastle.cms;version=0;resolution:=optional,
org.bouncycastle.cms.jcajce;version=0;resolution:=optional,
org.slf4j;version=0;resolution:=optional,
org.w3c.dom;version=0;resolution:=optional,
org.xml.sax;version=0;resolution:=optional,
com.atlassian.plugin.osgi.bridge.external
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Spring-Context: *
Tool: Bnd-3.5.0.201709291849
#-----------------------------------------------------------------------
What could be causing this? It is especially weird since reverting the changes to pom.xml did not get rid of the error.
The error was caused by the ImageJ dependency that I had. Apparently some of their classes use the default package which does not play well with maven. Removing the dependency fixes the issue.
I had a similar issue. To find out which dependency may prevent OSGi packaging to work, review error message like Classes found in the wrong directory: {META-INF/versions/9/module-info.class=module-info}
Using jcfind to identify its origin, as an example:
./target/classes/META-INF/lib/classgraph-4.8.43.jar META-INF/versions/9/module-info.class
I am contacting parent POM provider to get this fixed.
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.
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 run a cxf bundle in karaf. It says that the package org.apache.ws.commons.schema is missing but the appropiate bundle is already installed (servicemix bundle)
I dont know why the dependency is not solved if the bundle 785 (xmlschema) is activated. Do I need to include something else or do I have some sort of configuration problem?
OSGi>features:install idb
Refreshing bundles org.springframework.jms (104)
Error executing command: Could not start bundle
mvn:org.apache.cxf/cxf-bundle-minimal/2.2.9 in feature(s)
cxf-bundle-minimal-2.6.0: Unresolved constraint in bundle
org.apache.cxf.bundle-minimal [832]: Unable to resolve 832.0:
missing requirement [832.0] package;
(&(package=org.apache.ws.commons.schema)(version>=1.4.0)(!(version>=2.0.0)))
OSGi>osgi:info 785
Apache ServiceMix Bundles: xmlschema-1.4.3 (785)
------------------------------------------------
OSGi>osgi:headers 785
Apache ServiceMix Bundles: xmlschema-1.4.3 (785)
------------------------------------------------
Manifest-Version = 1.0
Bnd-LastModified = 1237594240914
Tool = Bnd-0.0.255
Built-By = gnodet
Build-Jdk = 1.5.0_16
Created-By = Apache Maven Bundle Plugin
Bundle-Vendor = The Apache Software Foundation
Bundle-Name = Apache ServiceMix Bundles: xmlschema-1.4.3
Bundle-DocURL = http://www.apache.org/
Bundle-Description = This bundle simply wraps xmlschema-1.4.3.jar.
Bundle-SymbolicName = org.apache.servicemix.bundles.xmlschema
Bundle-Version = 1.4.3.1
Bundle-License = http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-ManifestVersion = 2
Import-Package =
javax.xml.namespace,
javax.xml.parsers,
javax.xml.transform,
javax.xml.transform.dom,
javax.xml.transform.sax,
javax.xml.transform.stream,
org.apache.ws.commons.schema;version=1.4.3,
org.apache.ws.commons.schema.constants;version=1.4.3,
org.apache.ws.commons.schema.extensions;version=1.4.3,
org.apache.ws.commons.schema.resolver;version=1.4.3,
org.apache.ws.commons.schema.utils;version=1.4.3,
org.w3c.dom,
org.xml.sax
Export-Package =
org.apache.ws.commons.schema.resolver;uses:=org.xml.sax;version=1.4.3,
org.apache.ws.commons.schema.utils;
uses:="org.apache.ws.commons.schema,
javax.xml.namespace,
org.w3c.dom";
version=1.4.3,
org.apache.ws.commons.schema;
uses:="org.xml.sax,
javax.xml.namespace,
org.w3c.dom,
javax.xml.transform,
org.apache.ws.commons.schema.extensions,
javax.xml.transform.dom,
javax.xml.transform.sax,
org.apache.ws.commons.schema.resolver,
org.apache.ws.commons.schema.utils,
javax.xml.parsers,
org.apache.ws.commons.schema.constants,
javax.xml.transform.stream";
version=1.4.3,
org.apache.ws.commons.schema.constants;
uses:=javax.xml.namespace;
version=1.4.3,
org.apache.ws.commons.schema.extensions;
uses:="org.apache.ws.commons.schema,
javax.xml.namespace,
org.w3c.dom";
version=1.4.3
The CXF version you use seems to be quite old. Can you test this with the most recent CXF version? Btw. What Karaf version are you using?
First of all, what is the state of bundle 785 (xmlschema-1.4.3) ?
If the state is resolved or active, it is ok; if it is only "installed", then there is a problem with it and the packages it exports are not available in the system.
Second, check who provides the packages imported by bundle 785. (org.w3c.dom etc)
You could have the following situation:
If bundle idb imports e.g. org.w3c.dom from one source, and xmlschema-1.4.3 imports them from another (e.g. different versions are available at the same time, or both the framework itself and some additional bundle provide it) then the framework won't resolve the idb bundle with the package from xmlschema-1.4.3, because this would lead to a ClassCastException later on.