# \[solved\] Confusion about Component activation behaviour differences between bndtools and PDE

**URL:** <https://bnd.discourse.group/t/solved-confusion-about-component-activation-behaviour-differences-between-bndtools-and-pde/437>\
**Category:** GENERAL\
**Created:** [April 11, 2024, 4:01pm UTC](https://bnd.discourse.group/t/solved-confusion-about-component-activation-behaviour-differences-between-bndtools-and-pde/437 "2024-04-11T16:01:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkoerkel](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/jkoerkel/32/222_2.png) [@jkoerkel](https://bnd.discourse.group/u/jkoerkel)\
**Post date:** [April 11, 2024, 4:01pm UTC](https://bnd.discourse.group/t/solved-confusion-about-component-activation-behaviour-differences-between-bndtools-and-pde/437/1 "2024-04-11T16:01:43Z")

</div>

Hello everyone!

I am in the process of converting 95 bundles created and developed within a PDE workspace over the past ~20 years to bndtools. Quite big task, nice to learn a lot of stuff, also nice to get a lot of headaches, but mostly the good-pain kind 🙂  
So I’ve been running into lots of weird problems mostly having to do with dependency management (and dealing with ooooold libraries) and the differences between how PDE and bndtools approach/implement OSGi…  
So far so good, other than the _abysmal_ state of bndtools’ documentation, which I knew before will be a tough pill to swallow, mostly by finding out about some of the cool stuff that is only partially documented, I’ve actually come very far and am pretty happy about how everything turned out. That is until I just found a potential dealbreaker, which if not resolvable might have me need to throw in the towel for economic reasons.  
Edit: The previous sentence was exaggerated, but such a major redesign of our main product is gonna stir up big discussions in our team.  
I’m running into a problem where some of our bundles are fragments containing annotated DS @Components, which do get activated in the PDE workspace, yet not in bndtools.  
One of their `Fragment-Host`s has `Eclipse-ExtensibleAPI: true` in its Manifest, yet I don’t know whether this is the reason its fragments’ @Components get activated, while that doesn’t happen in bndtools.

I’ve come pretty far in this whole conversion, 74 of those bundles are sitting happily in my bndtools workspace, not throwing errors during build time, all resolving as they should (or how I at least guess they should) in runtime also running smoothly until services get called with their @Component annotated implementations being located in a fragment bundle, as these somehow don’t end up in the OSGi service registry.  
Of course this leads to functionality breaking, as `org.osgi.framework.ServiceException`s get thrown left right and center.

Can I, without restructuring those fragments to independent bundles, replicate the PDE behaviour in bndtools?

Cheers  
Julian

---

<div class="post-metadata">

**Author:** ![chrisrueger](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/chrisrueger/32/18_2.png) [@chrisrueger](https://bnd.discourse.group/u/chrisrueger)\
**Post date:** [April 11, 2024, 5:24pm UTC](https://bnd.discourse.group/t/solved-confusion-about-component-activation-behaviour-differences-between-bndtools-and-pde/437/2 "2024-04-11T17:24:24Z")

</div>

Hi @jkoerkel ,

not that I know an answer, but a few questions:

I think it is a limitation of OSGi that Fragments do not participate in normal bundle lifecycle.

Does your current Fragment bundle really need to be fragment bundle? If yes, what was the reason?

Could you move the `@Components` class from the Fragment bundle to another normal bundle?

---

<div class="post-metadata">

**Author:** ![chrisrueger](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/chrisrueger/32/18_2.png) [@chrisrueger](https://bnd.discourse.group/u/chrisrueger)\
**Post date:** [April 11, 2024, 6:26pm UTC](https://bnd.discourse.group/t/solved-confusion-about-component-activation-behaviour-differences-between-bndtools-and-pde/437/3 "2024-04-11T18:26:08Z")

</div>

> [@jkoerkel](#):
>
> without restructuring those fragments to independent bundles

OK sorry I overread your most important sentence. Hmm not sure you can avoid that.

Since the fragment shares the same classpath with the host (the host can see classes in its fragments) you may do some classpath [classloader scanning tricks](https://stackoverflow.com/questions/3222638/get-all-of-the-classes-in-the-classpath) in the host and find specific classes in the fragments and instanciate them.

I am sure you already found [this article](https://vogella.com/blog/osgi-bundles-fragments-dependencies/) by @fipro78 which I think describes your problem.

Edit:  
Just in case you don’t know: The [OSGi bnd Snapshot Viewer](https://bnd.bndtools.org/snapshot.html) was a valueable tool in a few cases when I migrated to bndtools.

---

<div class="post-metadata">

**Author:** ![jkoerkel](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/jkoerkel/32/222_2.png) [@jkoerkel](https://bnd.discourse.group/u/jkoerkel)\
**Post date:** [April 12, 2024, 7:27am UTC](https://bnd.discourse.group/t/solved-confusion-about-component-activation-behaviour-differences-between-bndtools-and-pde/437/4 "2024-04-12T07:27:50Z")

</div>

> I think it is a limitation of OSGi that Fragments do not participate in normal bundle lifecycle.

Yeah we had a lot of issues in the codebase where we deviate from how things actually _should_ be done in OSGi, yet this one unfortunately is a little larger then my previous problems in this conversion…

> Does your current Fragment bundle really need to be fragment bundle? If yes, what was the reason?

… cause let’s talk more like… 20ish fragments or so. Why we did this really only makes sense when talking about what our products are supposed to do in German (not at liberty to explain) and suddenly the idea of Fragments extending their hosts’ apis like this becomes a no-brainer, yet the moment this is taken out of a PDE context, it obviously fails. So now I’m probably gonna be overstaying my welcome with my team because this entails a rather substantial redesign of our main product, where what I was supposed to do is just to make a different build system work with our existing products, so no manual upkeep of Manifests is necessary and use its more strict warnings to _after_ conversion, not before, fix our problems with how we’ve been doing some key aspects of OSGi development not completely the right way.

> Could you move the `@Components` class from the Fragment bundle to another normal bundle?

That unfortunately grows the host bundle substantially and the split into fragments was done so we have a better overview of our general project structure. So this would just dissolve the fragments and put them back in an already already very big host bundle…

---

<div class="post-metadata">

**Author:** ![juergen-albert](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/juergen-albert/32/20_2.png) [@juergen-albert](https://bnd.discourse.group/u/juergen-albert)\
**Post date:** [April 12, 2024, 11:46am UTC](https://bnd.discourse.group/t/solved-confusion-about-component-activation-behaviour-differences-between-bndtools-and-pde/437/5 "2024-04-12T11:46:09Z")

</div>

Interesting case. I never realized, that Components inside a Fragment don’t work OOTB. This ahs nothing todo with bnd though. SCR does simply not look for a `Service-Component` Header in Fragments. The solution is rather simple though, as I just found out. Add `Service-Component: OSGI-INF/*` to the Manifest of your Host Bundle and now it will work as you expect.

---

<div class="post-metadata">

**Author:** ![jkoerkel](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/jkoerkel/32/222_2.png) [@jkoerkel](https://bnd.discourse.group/u/jkoerkel)\
**Post date:** [April 12, 2024, 12:19pm UTC](https://bnd.discourse.group/t/solved-confusion-about-component-activation-behaviour-differences-between-bndtools-and-pde/437/6 "2024-04-12T12:19:21Z")

</div>

That explains a lot, because in the PDE projects, their manifests have `Service-Component: OSGI-INF/components/*.xml` set, yet I didn’t do that in my bnd.bnd-files, as the `Service-Component` Header is set by bndtools. Then I’ll add that back and report back whether that solves my problem.

Thank you!

[Related SO-Answer](https://stackoverflow.com/a/42062399)

---

<div class="post-metadata">

**Author:** ![jkoerkel](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/jkoerkel/32/222_2.png) [@jkoerkel](https://bnd.discourse.group/u/jkoerkel)\
**Post date:** [April 12, 2024, 12:44pm UTC](https://bnd.discourse.group/t/solved-confusion-about-component-activation-behaviour-differences-between-bndtools-and-pde/437/7 "2024-04-12T12:44:31Z")

</div>

That has solved my problem. Thanks a lot!
