Take the 2-minute tour ×

Is it possible to import package from another bundle without calling its activator? This package isn't required any bundle initializations. I understand that this is bad design but I cannot change it.


org.osgi.framework.BundleException: The activator my-package.Activator for bundle my-bundle is invalid
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:157)  
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:750)  
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:352)  
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:370)  
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1068)  
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:557)  
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:464)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:248)  
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:445)  
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:220)  
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:330)
share|improve this question

3 Answers 3

Yes, it is possible, it is allowed by the OSGi spec, and it is not even bad practice.

Let me see if I have understand you right. You have bundle A, which exports a package in its manifest, and bundle B, which imports it. You want to do it without starting bundle A, right?

Yes, this is possible. If the only purpose of bundle A is to provide some java classes and packages, like a library, it may even not have an activator. According to the OSGi spec all exported packages of a bundle are available to other bundles right after the bundle goes in the resolved state (i.e. it is installed, dependencies are resolved, but it is not yet started).

The state of bundle B, which uses bundle A, doesn't matter. It also doesn't matter whether bundle B uses classes from the imported package or not. You also don't have to do anything special, just declare the dependency in the usual OSGi way:

Bundle A manifest: Export-Package: com.acme.aaa

Bundle B manifest: Import-Package: com.acme.aaa

You should install bundle A and check whether it has gone in the RESOLVED state, i.e. whether its dependencies are satisfied in the system. If yes, you can leave it like this and use it in bundle B.

The people above probably confuse importing packages with using a SERVICE in OSGi. Providing a SERVICE (i.e. a "live" java object) requires the bundle to be started and its activator to be called. Just exporting packages doesn't.

share|improve this answer
I'm new in OSGI so can you explain me more? I have some class in bundle A that I use in bundle B. I am using launcher that (when I click add required bundles) adds bundle A to dependencies of B. Bundle A also has Activator (that I cannot delete but don't want to run). When I start launcher there is exception like: "where is activator for bundle A?" however I don't want to run it. –  bellum Jul 18 '12 at 9:51
Question is: where and when (not in runtime in bundle B?) I must check that bundle A is in the RESOLVED state? –  bellum Jul 18 '12 at 9:57
I'm not sure what setup you're using. Can't you start the OSGi framework by itself and then install your bundles by hand? You should have access to some command console or smth similar where you can list the bundles and ask their state. Check if you can enable one in your launcher? I can show you how this is done for example with this framework - prosyst.com/index.php/de/html/content/97/… –  pooh Jul 18 '12 at 10:41
I must do this in that way that anybody else can later run my launcher per one click. So is this possible using only launcher? –  bellum Jul 18 '12 at 11:19
It should be possible... It depends on whether your launcher allows you to configure the order and state of the bundles to be installed. Just a crazy idea : maybe you could wrap bundle A as an internal jar in another jar? You would need to declare Export-Package and Bundle-ClassPath:.,name_of_jar_A.jar In this way you'll be able to control what happens when the bundle is started. Since your wrapper bundle won't have an activator, it will be started successfully without calling the activator of the internal jar (since you didn't declare it in your new manifest). –  pooh Jul 18 '12 at 11:26

According to the OSGi spec, this is not possible. Your only options are eager and lazy activation, both having happened before you observe any class from the bundle.

BTW If you are really only importing a package without ever referencing any classes, then a lazy-activated bundle will not get activated. I doubt this is your case, though.

share|improve this answer
Actually I must use one class from this imported package. –  bellum Jul 18 '12 at 9:15
Incorrect. It's completely possible. Activation requires resolution but resolution does not (cannot!) require activation. –  Neil Bartlett Jul 18 '12 at 17:27
@neilbartlett So my error is in thinking that without the bundle-activationpolicy the bundle is eagerly activated. In fact, then it is not activated at all except explicitly? I must admit that spec page has always confused me. –  Marko Topolnik Jul 18 '12 at 18:55
@MarkoTopolnik Bundles are never activated unless somebody explicitly activates them by calling bundle.start(). –  Neil Bartlett Jul 19 '12 at 1:17
@MarkoTopolnik That would only happen if somebody has previously called start(Bundle.START_ACTIVATION_POLICY). To reiterate: bundles NEVER start unless somebody calls start on them. The reason you never explicitly started your bundles in Eclipse RCP is because another bundle (the p2 "simpleconfigurator" bundle) starts them. –  Neil Bartlett Jul 19 '12 at 10:07

If a bundle is in the resolved state, you can import its package, it hasn't been started (yet?).

So: Just install the bundle, and just don't start it. I guess it depends on the context if that is a good idea or not.

share|improve this answer

Your Answer


