# How to exclude files/packages from the JAR?

**URL:** <https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300>\
**Category:** GENERAL\
**Created:** [April 6, 2023, 8:04am UTC](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300 "2023-04-06T08:04:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rec](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/rec/32/155_2.png) [@rec](https://bnd.discourse.group/u/rec)\
**Post date:** [April 6, 2023, 8:04am UTC](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300/1 "2023-04-06T08:04:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rec](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/rec/32/155_2.png) [@rec](https://bnd.discourse.group/u/rec)\
**Post date:** [May 16, 2023, 1:49pm UTC](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300/2 "2023-05-16T13:49:23Z")

</div>

**Ping** anybody? 🛎

---

<div class="post-metadata">

**Author:** ![pkriens](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/pkriens/32/3_2.png) [@pkriens](https://bnd.discourse.group/u/pkriens)\
**Post date:** [May 16, 2023, 2:24pm UTC](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300/3 "2023-05-16T14:24:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rec](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/rec/32/155_2.png) [@rec](https://bnd.discourse.group/u/rec)\
**Post date:** [May 17, 2023, 9:59am UTC](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300/5 "2023-05-17T09:59:49Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![rec](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/rec/32/155_2.png) [@rec](https://bnd.discourse.group/u/rec)\
**Post date:** [May 17, 2023, 2:17pm UTC](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300/6 "2023-05-17T14:17:28Z")

</div>

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… 😕

---

<div class="post-metadata">

**Author:** ![rec](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/rec/32/155_2.png) [@rec](https://bnd.discourse.group/u/rec)\
**Post date:** [May 17, 2023, 3:37pm UTC](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300/7 "2023-05-17T15:37:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pkriens](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/pkriens/32/3_2.png) [@pkriens](https://bnd.discourse.group/u/pkriens)\
**Post date:** [May 19, 2023, 7:48am UTC](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300/8 "2023-05-19T07:48:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rec](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/rec/32/155_2.png) [@rec](https://bnd.discourse.group/u/rec)\
**Post date:** [May 22, 2023, 6:28am UTC](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300/9 "2023-05-22T06:28:08Z")

</div>

> <https://github.com/bndtools/bnd/issues/5668>
>
> I have a workspace with a large number of projects (\> 100) in Eclipse. These are… Maven projects that use the bnd-maven-plugin to turn my JAR artifacts into OSGI bundles.
> 
> The \`bnd-jar\` goal does \[not support including/excluding files\](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300/8) from the JAR. Hence, I was advised to try not using the \`bnd-jar\` goal, but rather to only use the \`process-classes\` goal to generate the manifest. Not using the \`bnd-jar\` reinstates the default \`maven-jar-plugin\` execution. So I could configure my includes/excludes there. So far so good.
> 
> However, I noticed that after removing the \`bnd-jar\` execution to reinstate the \`maven-jar-plugin\` execution, the Eclipse incremental build would get stuck in an endless build loop at a random Maven/OSGI/bnd project, endlessly logging the execution of the \`jar:jar\` goal and then re-scheduling another build of the same module as soon as the JAR had been built. I could abort the incremental build from the progress view, but unless I spammed cancel on the rapidly respawning builds, it would get hung again in the same or in another random Maven/OSGI/bnd project. Turning off auto-build in Eclipse would temporarily resolve the issue, but turning it back on, the IDE would immediately re-enter the endless build loop. Trying to refresh, update, rebuild projects before turning on auto-build again had no effect. 
> 
> I did investigate the situation from a couple of angles and looked at excluding other plugins as possible sources for the loop. That allowed me to improve my build in various ways, but eventually did not resolve the problem.
> 
> Switching back to using the \`bnd-jar\` execution resolved the problem. 
> 
> As far as I could tell (don't ask me exactly how - I believe I had a peek at the stack trace in VisualVM), it seems that the \`jar:jar\` execution that seems to be scheduled when \`bnd-jar\` is not used is triggered by the \`BND Decorator\` in Eclipse.
> 
> \*\*Environment\*\*
> Eclipse IDE for Java Developers (includes Incubating components)
> Version: 2023-03 (4.27.0)
> Build id: 20230309-1520
> 
> \<img width="1150" alt="Screenshot 2023-05-22 at 08 23 43" src="https://github.com/bndtools/bnd/assets/1410238/66882b72-1eeb-4b5d-8cc4-ad3de5349396"\>

---

<div class="post-metadata">

**Author:** ![rec](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/rec/32/155_2.png) [@rec](https://bnd.discourse.group/u/rec)\
**Post date:** [September 3, 2025, 5:51pm UTC](https://bnd.discourse.group/t/how-to-exclude-files-packages-from-the-jar/300/10 "2025-09-03T17:51:11Z")

</div>

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.

```auto
<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](https://github.com/bndtools/bnd/issues/6794)
