# How to warp a bundle such that its BCP persists

**URL:** https://bnd.discourse.group/t/how-to-warp-a-bundle-such-that-its-bcp-persists/479
**Category:** GENERAL
**Created:** [October 18, 2024, 3:19pm UTC](https://bnd.discourse.group/t/how-to-warp-a-bundle-such-that-its-bcp-persists/479 "2024-10-18T15:19:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Nuw](https://avatars.discourse-cdn.com/v4/letter/n/a6a055/32.png) [@Nuw](https://bnd.discourse.group/u/Nuw)
#### Post date: [October 18, 2024, 3:19pm UTC](https://bnd.discourse.group/t/how-to-warp-a-bundle-such-that-its-bcp-persists/479/1 "2024-10-18T15:19:30Z")

</div>

Hello everyone,

I’ve been trying to wrap an existing OSGI-bundle B, adding content in the process (yes has to be in the existing bundle) and maintain the original Bundle-Classpath (BCP).

My approach currently is that I unroll bundle B like so:  
`-includeresource: @B*.jar`

This results in a wrapped bundle that contains all the data we want to have it contain. Unfortunately, by doing so the original BCP is lost.

I tried setting the BCP manually via:  
`Bundle-ClassPath: .,${lsr;./target/classes/;*.jar}`

This approach only works if the bundle B was already unrolled previously, or in other words:  
The includeresouce instruction is executed after the BCP-Header field is evaluated.

I am sure that I am missing something here but I couldn’t find another way of getting the correct result.  
Does anybody know a better approach? Or how I could tell bndtools to evaluate the BCP-Header after the includeresource instruction?

Thank you very much and have a great weekend!  
Nuw

P.S. I also tried out if I could use the -includeresource instruction to include and add the contained jars of the original bundle directly, but the `lib:=true` flag doesn’t seem to work for files from within another depency.  
Example:

```auto
-includeresource: \
	@B*.jar!/!*.jar,\
	@B*.jar!/*.jar;lib:=true

```

---

<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: [October 23, 2024, 8:37pm UTC](https://bnd.discourse.group/t/how-to-warp-a-bundle-such-that-its-bcp-persists/479/2 "2024-10-23T20:37:11Z")

</div>

Hi @Nuw ,

> [@Nuw](#):
>
> `@B*.jar`

in `@B*.jar` the `@` refers to [extractFromJar()](https://github.com/bndtools/bnd/blob/master/biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java#L974) which currently does not handle the `lib:=true` directive. And `lib:=true` basically seems to mean “append to the Bundle-Classpath”.

`lib:=true` seems only to be handled without the `@` when you [copy directly](https://github.com/bndtools/bnd/blob/master/biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java#L1429) without extracting it, and then the Bundle-Classpath is appended.  
Basically as in [those examples](https://bnd.bndtools.org/instructions/includeresource.html#assignment-form):

 ![image](https://global.discourse-cdn.com/free1/uploads/bnd/original/1X/557036ffb2e4bc1533ced59b10f38f2ba29c1152.png)

Question:

Would something like

```auto
if (isTrue(extra.get(LIB_DIRECTIVE))) {
			setProperty(BUNDLE_CLASSPATH, append(getProperty(BUNDLE_CLASSPATH, "."), path));
		}

```

also make sense for the extract / unroll .jar case?  
e.g.

`@B*.jar!/*.jar;lib:=true`

I am currently deep in another [-includeresource PR](https://github.com/bndtools/bnd/pull/6326) and could have a look.

@pkriens

---

<div class="post-metadata">

### Author: ![Nuw](https://avatars.discourse-cdn.com/v4/letter/n/a6a055/32.png) [@Nuw](https://bnd.discourse.group/u/Nuw)
#### Post date: [October 24, 2024, 7:42am UTC](https://bnd.discourse.group/t/how-to-warp-a-bundle-such-that-its-bcp-persists/479/3 "2024-10-24T07:42:24Z")

</div>

Hi chrisrueger!

As some food for thought: If you unroll a bundle that itself has a BCP, why not use that as the initial BCP when processing the bnd-instructions?

In that case there’s no need for the LIB\_DIRECTIVE support for my use-case. But IMHO it still makes sense for others.

Thanks and have a great day!  
Nuw
