How to include a config file in the "META-INF/services" folder of a JAR using Maven

Create a new source folder with the location src/main/resources, then create your META-INF/services folder in there and drop in your FQCN file. This should copy them into the jar file automatically. So you'll have:

Project
| src
| | main
|   | java
|     | [your source code]
|   | resources
|     | META-INF
|       | services
|         | [your service files]

It's worth noting that this applies to Gradle projects with the default source sets as well.


By default Maven looks for resources at:

src/main/resources

So put it at

src/main/resources/META-INF/services

Alternatively, if your project does not use a standard directory structure (or your simply wish to have alternate resource directories), you can specify resource directories manually the POM file.

For example, if your META-INF/services is located in a folder called resources which lies in the root of your project directory, could specify it as follows:

<project>
...
  <build>
    ...
    <resources>
      <resource>
        <directory>resources</directory>
      </resource>
    </resources>
    ...
  </build>
  ...
</project>

You can use this to specify several directories by adding multiple <resource> elements.