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

前端 未结 3 1325
-上瘾入骨i
-上瘾入骨i 2020-12-12 23:36

I\'m working on a Java project in Eclipse, which is built using Maven. I\'m using some recycled code from an older project, and one of these classes looks for a file in the

相关标签:
3条回答
  • 2020-12-12 23:51

    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.

    0 讨论(0)
  • 2020-12-13 00:00

    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.

    0 讨论(0)
  • 2020-12-13 00:01

    By default Maven looks for resources at:

    src/main/resources
    

    So put it at

    src/main/resources/META-INF/services
    
    0 讨论(0)
提交回复
热议问题