Fork me on GitHub

How to Include or Exclude Content from a JAR Artifact

Add <includes>/<include> or <excludes>/<exclude> in your pom.xml. These elements specify the fileset patterns to include or exclude.

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>4.0.0-beta-2</version>
        <configuration>
          <includes>
            <include>**/service/*</include>
          </includes>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

The patterns must be relative to the path for the plugin's classesDirectory parameter. By default, the syntax is the same as Maven 3, where ** can match any number of directories including zero. An alternative syntax can be specified by prefixing the pattern with glob:, regex: or any other syntax added through the service provider mechanism. See FileSystem.getPathMatcher(String) in Java NIO for more information.