# Includeresource: Exclude OSGI-INF resources

**URL:** <https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263>\
**Category:** GENERAL\
**Created:** [September 27, 2022, 4:14pm UTC](https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263 "2022-09-27T16:14:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwin](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/kwin/32/142_2.png) [@kwin](https://bnd.discourse.group/u/kwin)\
**Post date:** [September 27, 2022, 4:14pm UTC](https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263/1 "2022-09-27T16:14:09Z")

</div>

I am trying to wrap multiple osgi bundles into a single uber-jar bundle.  
From some source bundles I want to strip the declarative services being defined in folder OSGI-INF.

I tried the following instructions in the bnd file:

```auto
-includeresource: @mybundle-1.0.0.jar!/!(OSGI-INF/*), ...

```

But still the OSGI-INF from mybundle ends up in the resulting bundle. I guess this is because the services are referenced in the META-INF/MANIFEST.MF. For all other regular folders the exclusions work properly.

How can I build an uber-jar from multiple bundles but leaving out some declarative services? Is there some special instruction or bnd plugin for it or do I rather have to use something like maven-shade-plugin?

---

<div class="post-metadata">

**Author:** ![bjhargrave](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/bjhargrave/32/10_2.png) [@bjhargrave](https://bnd.discourse.group/u/bjhargrave)\
**Post date:** [September 27, 2022, 5:48pm UTC](https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263/2 "2022-09-27T17:48:54Z")

</div>

> [@kwin](#):
>
> `@mybundle-1.0.0.jar!/!OSGI-INF/*`

doesn’t work? Not sure what you meant by using the parentheses.

---

<div class="post-metadata">

**Author:** ![kwin](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/kwin/32/142_2.png) [@kwin](https://bnd.discourse.group/u/kwin)\
**Post date:** [September 27, 2022, 5:53pm UTC](https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263/3 "2022-09-27T17:53:27Z")

</div>

> [@kwin](#):
>
> /!OSGI-INF/\*

Same result, unfortunately. The OSGI-INF is still part of the destination bundle.

---

<div class="post-metadata">

**Author:** ![bjhargrave](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/bjhargrave/32/10_2.png) [@bjhargrave](https://bnd.discourse.group/u/bjhargrave)\
**Post date:** [September 27, 2022, 6:16pm UTC](https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263/4 "2022-09-27T18:16:31Z")

</div>

Are you sure Bnd is not regenerating DS, Metatype, etc from the jar contents? You may need to disable annotation processing by Bnd. e.g.

`-dsannotations:`  
`-metatypeannotations:`

---

<div class="post-metadata">

**Author:** ![rotty3000](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/rotty3000/32/16_2.png) [@rotty3000](https://bnd.discourse.group/u/rotty3000)\
**Post date:** [September 27, 2022, 8:13pm UTC](https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263/5 "2022-09-27T20:13:00Z")

</div>

note that, with @bjhargrave 's suggestion, you can use negative package syntax to prevent only certain packages from being analyzed by certain plugins:

```nohighlight
-dsannotations: !this.package, *
-metatype: !this.package, *

```

---

<div class="post-metadata">

**Author:** ![kwin](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/kwin/32/142_2.png) [@kwin](https://bnd.discourse.group/u/kwin)\
**Post date:** [September 27, 2022, 8:24pm UTC](https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263/6 "2022-09-27T20:24:33Z")

</div>

Thanks a lot for that pointer. Indeed the DS and metatype metadata were regenerated from the given bundle. For some reason I assumed that DS annotations had a SOURCE retention policy ([RetentionPolicy (Java Platform SE 8 )](https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/RetentionPolicy.html#SOURCE))  
With

```auto
-dsannotations:
-metatype:

```

I could disable generating DS component metadata but the metatype is still being generated for some reason…

---

<div class="post-metadata">

**Author:** ![bjhargrave](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/bjhargrave/32/10_2.png) [@bjhargrave](https://bnd.discourse.group/u/bjhargrave)\
**Post date:** [September 27, 2022, 8:54pm UTC](https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263/7 "2022-09-27T20:54:22Z")

</div>

Oops. Its actually `-metatypeannotations:`.

---

<div class="post-metadata">

**Author:** ![kwin](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/kwin/32/142_2.png) [@kwin](https://bnd.discourse.group/u/kwin)\
**Post date:** [September 27, 2022, 9:30pm UTC](https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263/8 "2022-09-27T21:30:58Z")

</div>

Thanks again. Would you mind adding an entry for that instruction to [Instruction Index | bnd](https://bnd.bndtools.org/chapters/825-instructions-ref.html)?

---

<div class="post-metadata">

**Author:** ![bjhargrave](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/bjhargrave/32/10_2.png) [@bjhargrave](https://bnd.discourse.group/u/bjhargrave)\
**Post date:** [September 27, 2022, 9:39pm UTC](https://bnd.discourse.group/t/includeresource-exclude-osgi-inf-resources/263/9 "2022-09-27T21:39:56Z")

</div>

Done: [docs: Fix documentation for Metatype annotation processing instructions by bjhargrave · Pull Request #5380 · bndtools/bnd · GitHub](https://github.com/bndtools/bnd/pull/5380)
