In Maven how to exclude resources from the generated jar?

后端 未结 8 1158
余生分开走
余生分开走 2020-11-30 01:46

When I create an executable jar with dependencies (using this guide), all properties files are packaged into that jar too. How to stop it from happening? Thanks.

UPD

8条回答
  •  难免孤独
    2020-11-30 02:03

    By convention, the directory src/main/resources contains the resources that will be used by the application. So Maven will include them in the final JAR.

    Thus in your application, you will access them using the getResourceAsStream() method, as the resources are loaded in the classpath.

    If you need to have them outside your application, do not store them in src/main/resources as they will be bundled by Maven. Of course, you can exclude them (using the link given by chkal) but it is better to create another directory (for example src/main/external-resources) in order to keep the conventions regarding the src/main/resources directory.

    In the latter case, you will have to deliver the resources independently as your JAR file (this can be achieved by using the Assembly plugin). If you need to access them in your Eclipse environment, go to the Properties of your project, then in Java Build Path in Sources tab, add the folder (for example src/main/external-resources). Eclipse will then add this directory in the classpath.

提交回复
热议问题