OSGi Bundle not get resolved automatically - java

I have a simple OSGi bundle written and here is the source file. When I install it in a equinox OSGi container it does not get resolved it automatically. Can someone explain what I'm doing wrong here??.
package org.sample.api;
/**
* Created on 3/11/14.
*/
public interface Hello {
void sayHello();
}
This is the pom.xml file of the bundle.
<?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">
<parent>
<artifactId>osgi</artifactId>
<groupId>osgi</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sample-api</artifactId>
<version>1.0</version>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.5</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Vendor>Sample Inc</Bundle-Vendor>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Export-Package>
org.sample.api*;version=1.0.0
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
MANIFEST.MF
Manifest-Version: 1
Bnd-LastModified: 1396602001251
Build-Jdk: 1.6.0_45
Built-By: Zeus
Bundle-ManifestVersion: 2
Bundle-Name: sample-api
Bundle-SymbolicName: sample-api
Bundle-Vendor: Sample Inc
Bundle-Version: 1.0.0
Created-By: Apache Maven Bundle Plugin
Export-Package: org.sample.api;version="1.0.0"
Tool: Bnd-1.43.0
This is the bundle installation console output
Bundle id is 7
RegisteredServices null
ServicesInUse null
LoaderProxy sample-api; bundle-version="1.0.0"
Fragments null
ClassLoader null
Version 1.0.0
LastModified 1396605985751
Headers Bnd-LastModified = 1396602001251
Build-Jdk = 1.6.0_45
Built-By = Zeus
Bundle-ManifestVersion = 2
Bundle-Name = sample-api
Bundle-SymbolicName = sample-api
Bundle-Vendor = Sample Inc
Bundle-Version = 1.0.0
Created-By = Apache Maven Bundle Plugin
Export-Package = org.sample.api;version="1.0.0"
Manifest-Version = 1
Tool = Bnd-1.43.0
BundleContext null
BundleId 7
StartLevel 1
SymbolicName sample-api
BundleData sample-api_1.0.0
KeyHashCode 7
StateChanging null
BundleDescription sample-api_1.0.0
Framework org.eclipse.osgi.framework.internal.core.Framework#65cb687f
ResolutionFailureException org.osgi.framework.BundleException: The bundle "sample-api_1.0.0 [7]" could not be resolved
Revisions [sample-api_1.0.0]
Key 7
ProtectionDomain null
Location file:/home/Zeus/idea-projects/osgi/sample-api/target/sample-api-1.0.jar
State 2
Bundle 7|Installed | 1|sample-api (1.0.0)

Please post the generated MANIFEST.MF from the jar. I cant see anything wrong with the pom.
If the bundle is not resolved, in what state is it then? Installed? One possible reason could be that some of the transitive dependencies of the bundle are not available on the container.
P.S: You may want to use the latest version 2.4.0 for the maven-bundle-plugin.
EDIT1
This is the manifest I got:
Manifest-Version: 1.0
Bnd-LastModified: 1396605817562
Build-Jdk: 1.7.0_45
Built-By: anshuman
Bundle-ManifestVersion: 2
Bundle-Name: sample-api
Bundle-SymbolicName: sample-api
Bundle-Vendor: Sample Inc
Bundle-Version: 1.0.0
Created-By: Apache Maven Bundle Plugin
Export-Package: org.sample.api;version="1.0.0"
Tool: Bnd-2.1.0.20130426-122213
EDIT2
I hope you are refreshing and starting the bundle after you install it.
refresh 7
start 7
where 7 is your bundle id.

Looks like you don't have a Activator with your bundle, at least your given sample doesn't contain one and your output for the generated Manifest doesn't contain a Bundle-Activator part. At this point I'd say your bundle is just in resolved state since it can't be active.

INSTALLED state is not an error condition. It just means that the bundle has been installed, which is true.
If you do see an actual error message, please provide the details.

Related

Dependency not installed when installing Eclipse

I am developing an Eclipse plugin. That is using UI and file resources. Which required org.eclipse.core.resources;bundle-version="3.8.101" and filed if this dependency is not available on target eclipse.
Eclipse version: Juno (for Android development).
I want to install this jar if not available on target Eclipse. So my plugin run without any issue for target Eclipse.
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ABC
Bundle-SymbolicName: ABC;singleton:=true
Bundle-Version: 1.0
Bundle-Activator: magic.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources;bundle-version="3.8.101"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
libs/java-json.jar,
libs/json-lib-2.4-jdk15.jar
Here is the error I got while installation
Cannot complete the install because one or more required items could not be found.
Software being installed: Feature 1.0.0 (com.confiz.android.codegen.feature.feature.group 1.0.0)
Missing requirement: Feature 1.0.0 (com.confiz.android.codegen.feature.feature.group 1.0.0) requires 'org.eclipse.core.resources 3.8.101' but it could not be found

How to add plugin to run configuration?

I try to build a java project with eclipse.
During the complilation I have error java.lang.RuntimeException: No application id has been found. So I read that I need to add required plugins. I went to Run Configuration -> Plug-ins tab, push button Add Required Plug-ins and then validate plug-ins. I have my own plugin in the project. So I get com.blablabla is missing. How can I add my plugin to plugins list?
UPD: MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: com.blabla.cc; singleton:=true
Bundle-Version: 0.0.0.REL
Bundle-Activator: com.blabla.ui.cc.Activator
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.core.expressions;bundle-version="3.4.1",
com.blabla.core,
com.blabla..shared,
com.blabla.ui.core,
com.blabla.ui,
org.eclipse.jface.text,
org.eclipse.ui.editors,
org.eclipse.ui.workbench.texteditor,
org.eclipse.core.filesystem,
org.eclipse.ui.ide,
org.eclipse.ui.views,
org.apache.axis,
org.eclipse.wst.xml.core
Eclipse-LazyStart: true
Bundle-ClassPath: lib/SCESchemaCodeCcWorkbench.jar,
lib/DebugUtils.jar,
bin,
icons,
myApplicationUI.jar,
lib/batik-awt-util.jar,
lib/batik-bridge.jar,
lib/batik-css.jar,
lib/batik-dom.jar,
lib/batik-ext.jar,
lib/batik-gvt.jar,
lib/batik-parser.jar,
lib/batik-script.jar,
lib/batik-svg-dom.jar,
lib/batik-swing.jar,
lib/batik-util.jar,
lib/batik-xml.jar,
lib/xml-apis-dom3.jar,
lib/batik-transcoder.jar,
lib/batik-anim.jar,
lib/batik-codec.jar,
lib/batik-extension.jar,
lib/batik-gui-util.jar,
lib/batik-svggen.jar,
lib/xml-apis-ext.jar
Export-Package: com.blabla.sce.schema.code.ccworkbench,
com.blabla.sce.schema.code.ccworkbench.types
Implementation-Version: 0.0.0.REL
Bundle-Localization: plugin

State of required bundle resolved instead of active

I have a bundle A that depends on bundle B. When code in bundle A runs and accesses a class from bundle B then the state of bundle B is resolved (4) instead of active (32) and the activator of bundle B didn't run as well. I assume there's something wrong the manifest of bundle B but I can't quite spot it.
This is the manifest of bundle B, generated with bnd.
Manifest-Version: 1.0
Export-Package: org.jboss.logging;uses:="org.osgi.framework,org.eclips
e.equinox.log,org.jboss.logmanager,org.apache.log4j,org.slf4j.spi,org
.slf4j";version="3.2.0.Beta1-SNAPSHOT"
Build-Timestamp: Sun, 17 Mar 2013 15:07:31 +0100
Tool: Bnd-0.0.357
Bundle-Name: JBoss Logging 3
Created-By: 1.7.0_10 (Oracle Corporation)
Bundle-Vendor: JBoss by Red Hat
Scm-Revision: 9e799bac390dbbf9c7cd55afe93dff9265fbed05
Bundle-Version: 3.2.0.Beta1-SNAPSHOT
Bnd-LastModified: 1363529254048
Bundle-ManifestVersion: 2
Bundle-Activator: org.jboss.logging.Activator
Bundle-Description: The JBoss Logging Framework
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-SymbolicName: org.jboss.logging.jboss-logging
Import-Package: org.apache.log4j;resolution:=optional,org.eclipse.equi
nox.log;resolution:=optional;version="1.0",org.jboss.logging;version=
"3.2",org.jboss.logmanager;resolution:=optional,org.osgi.framework;ve
rsion="1.7",org.slf4j;resolution:=optional;version="1.6",org.slf4j.sp
i;resolution:=optional;version="1.6"
Bundle-DocURL: http://www.jboss.org
This the manifest of bundle A generated with PDE.
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Sample-view
Bundle-SymbolicName: sample-view; singleton:=true
Bundle-Version: 1.0.0.qualifier
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui,
org.jboss.logging.jboss-logging
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Sigh. I bet you run on Equinox. In their eternal wisdom the Eclipse guys decided not to start bundles, being afraid it would overload the system. Trying to get a bundle started is REALLY overly complex in Eclipse. However, in your case there is a simple solution: OSGi Activation Policy. This will start your bundle when the first class is loaded. Just add to B
Bundle-ActivationPolicy: lazy

Apache Felix misses javax.sql.Datasource

i just migrated from Equinox to Apache Felix. Now there is the javax.sql.datasource class missing:
java.lang.NoClassDefFoundError: javax/sql/DataSource
My bundle is importing javax.sql in the manifest file and i tried to add the following line to the felix config:
org.osgi.framework.system.packages.extra=javax.sql
Is there any way to teach felix to export the bundle or is there a bundle that does it? It worked fine in Equinox even without the import statement in the manifest.
EDIT:
The manifest file:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Database
Bundle-SymbolicName: ...database
Bundle-Version: 1.0.0
Import-Package: javax.sql,
org.osgi.framework;version="1.3.0",
org.osgi.service.component;version="1.1.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: lib/mysql-connector-java-5.1.20-bin.jar,
.
Export-Package: ...database.model,
...database.service
Service-Component: OSGI-INF/component.xml
Thanks,
Daniel
Felix does already export this package.
More likely is that there may be something wrong with your Import-Package statement. You did state that your bundle imports the package, but please post a copy of your MANIFEST.MF to be sure.

cant start osgi bundle because import cannot be resolved

I have made a small API Bundle and a service bundle that should use the API.
In my maven pom.xml file, i added a dependecy for my api bundle in the correct version like this:
<dependency>
<groupId>at.foobar.osgi.api</groupId>
<artifactId>foobarapi</artifactId>
<version>1.0</version>
</dependency>
i'm using the maven-bundle plugin to create the bundles, and because of that i used mvn clean install to create by jar file.
The Manifest looks like this (the service):
Manifest-Version: 1.0
Private-Package: at.foobar.osgi.producer
Built-By: foobar
Tool: Bnd-0.0.238
Bundle-Name: foobarproducer
Created-By: Apache Maven Bundle Plugin
Bundle-Version: 1.0
Build-Jdk: 1.6.0_26
Bnd-LastModified: 1332185439257
Bundle-ManifestVersion: 2
Bundle-Activator: at.foobar.osgi.producer.Activator
Import-Package: at.foobar.osgi.api,org.osgi.framework;version="1.4"
Bundle-SymbolicName: at.foobar.osgi.producer.foobarproducer
which seems to be OK for me. The import is in there, so everything should be fine.
now i started up equinox and installed the API and the producer bundle.
Then i startet the API, which worked out fine. But when i want to start the Producer Service i get this error:
org.osgi.framework.BundleException: The bundle "at.foobar.osgi.producer.foobarproducer_1.0.0 [4]" could not be resolved. Reason: Missing Constraint: Import-Package: at.foobar.osgi.api; version="0.0.0"
It seems that the framework cannot find the api, but its installed and started?
Make sure that you are exporting the API packages, so that your service bundle can bind to them.
In your maven-bundle-plugin for the API bundle you should have something like:
<configuration>
<instructions>
<Import-Package>
*
</Import-Package>
<Export-Package>
at.foobar.osgi.api.*
</Export-Package>
</instructions>
</configuration>

Categories