Search code examples
javaosgiequinoxbnd

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

Solution

  • 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