reficio / p2-maven-plugin

Maven3 plugin that automates the third-party dependency management for Eclipse RCP
http://reficio.org
230 stars 97 forks source link

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

Open azaylamba opened 1 year ago

azaylamba commented 1 year ago

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"

sparsick commented 1 year ago

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

azaylamba commented 1 year ago

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?

sparsick commented 1 year ago

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.