p2-maven-plugin icon indicating copy to clipboard operation
p2-maven-plugin copied to clipboard

How to exclude certain file while generating a bundle from jar?

Open azaylamba opened this issue 2 years ago • 3 comments

Hi,

Can someone please help me with how to exclude certain file from the jar while generating OSGi bundle using p2-maven-plugin? I want to exclude INDEX.LIST file as it is causing issues in my project while loading the jar because of the jar name present in INDEX.LIST is different from the OSGi bundle. I tried using invalidfilenames instructions but it had no impact. I might be using it incorrectly. The instruction format I used is "<_invalidfilenames>INDEX.LIST</_invalidfilenames>"

azaylamba avatar Dec 09 '22 09:12 azaylamba

Hi @azaylamba

you have to do it with the underlying bnd tool. It is responsible for repacking of the jar.

Check the donotcopy option of it

https://bnd.bndtools.org/instructions/donotcopy.html

sparsick avatar Dec 09 '22 20:12 sparsick

Hi @sparsick, thanks for the quick response. I tried donotcopy option with p2-maven-plugin but it didn't work. Can you please confirm whether the plugin supports this or I would need to package my jar using bnd tool only and not using this plugin?

azaylamba avatar Dec 13 '22 05:12 azaylamba

Hi @azaylamba,

you can add BND instruction to your artifact configuration:

<artifact>
    <id>commons-io:commons-io:2.1</id>
    <transitive>true</transitive>
    <source>false</source>
    <override>false</override>
    <singleton>false</singleton>
    <instructions> <!-- here you can out bnd instruction-->
        <Import-Package>*;resolution:=optional</Import-Package>
        <Export-Package>*</Export-Package>
        <_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>
        <_removeheaders>Bnd-LastModified</_removeheaders>
        <_reproducible>true</_reproducible>
    </instructions>
    <excludes/>
</artifact>

Here it is described how to put bnd instruction to the plugin. P2 Plugin uses the mechanism of the maven bundle plugin.

I hope that helps.

sparsick avatar Dec 15 '22 15:12 sparsick