0

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
Philippe Marschall
  • 4,452
  • 1
  • 34
  • 52

1 Answers1

3

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
Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
  • Yes I'm running Equinonx and this is fixed the problem indeed. The documentation is a bit confusing http://wiki.osgi.org/wiki/Bundle-ActivationPolicy I got the impression that it would just delay running the activator. It doesn't say the bundle doesn't get activated at all if it's not present. – Philippe Marschall Mar 18 '13 at 14:25
  • 1
    Don't blame OSGi, Equinox is distinctly not OSGi in this case since in general all bundles should be started. – Peter Kriens Mar 18 '13 at 15:51
  • Philippe, I think I wrote that wiki page. The thing to remember is that OSGi itself *never* starts a bundle. You always need something else, e.g. a launcher or a management agent. The best practice is to always start all bundles, however Eclipse chooses not to do this if you don't have the `Bundle-ActivationPolicy`. In other words, Eclipse has layered its own additional semantics onto that manifest header. – Neil Bartlett Mar 18 '13 at 19:24
  • Yes, the Eclipse "configurator" is scared to start bundles for fear they will all take forever during Eclipse startup. But it will start bundles marked for lazy activation since it assumes their startup cost will be amortized... – BJ Hargrave Mar 18 '13 at 20:01
  • Sorry for dragging this discussion off-topic. What would already be a great improvement if Equinox better documented the current behaviour. I'm quite surprised by this. I googled a bit before asking this question and found nothing that suggested this is how things work in Equinox. – Philippe Marschall Mar 18 '13 at 21:04