How to exclude files/packages from the JAR?

I have some Maven modules that contain classes, but the JAR bundle artifacts they produce should not contain any of these classes - rather they should be limited including some data resources.

With the maven-bundle-plugin, I can exclude packages from the JAR by adding an exclude pattern to the Private-Package and Export-Package directives.

With the bnd-maven-plugin, it seems that this does not work. I also tries negative packages with -privatepackage and -includepackage, but that did also not have the desired effect.

Is it possible at all to tell the bnd-maven-plugin to exclude a particular package from the generated JAR?

Ping anybody? :bellhop_bell:

I think the newer plugins leave the actual content assembly to the default Maven JAR packager. In the old plugin, bnd created the JAR completely.

I have been able to resolve my problem by not executing the bnd-jar goal. This restores the execution of the maven-jar-plugin. The only thing I had to still do then was to configure the maven-jar-plugin to pick up the MANIFEST.MF file created by bnd-process.

Thanks!

I have the impression since turning off bnd-jar, m2e is much more inclined to enter an endless build loop for some random maven project… :confused:

I have the impression that the Bnd Decorator in the Bnd Eclipse plugins triggers a jar:jar execution if the bnd-jar goal does not suppress it and that this somehow causes the endless loop.

Can you file a bug? Please include as much information as you can.

Ok, here is the solution for this when using the jar goal.

The key is to disable the default behavior of the bnd plugin to include the classes folder and then use the correct syntax for -includeresources (which does not support ant-style wildcards, but still matches recursively) - so this works for including certain file types, but not matching certain directory paths.

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>bnd-test</groupId>
  <artifactId>bnd-rest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <plugins>
      <plugin>
        <groupId>biz.aQute.bnd</groupId>
        <artifactId>bnd-maven-plugin</artifactId>
        <version>7.1.0</version>
        <extensions>true</extensions>
        <executions>
          <execution>
            <id>jar</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <includeClassesDir>false</includeClassesDir>
          <bnd>
          -includeresource: /=src/main/resources/;filter:="**/*.json"
          </bnd>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Thanks to @chrisrueger @pkriens @rotty3000 for pointers.

See also Unable to build JAR containing only some resources and no classes · Issue #6794 · bndtools/bnd · GitHub

1 Like