Maven: how to place resource file together with jar?

前端 未结 3 511
醉酒成梦
醉酒成梦 2020-12-07 15:44

I have \\src\\main\\resources\\logback.xml file. When I run mvn package it is placed into the jar by default. How do I make Maven place it next to jar, not insi

相关标签:
3条回答
  • 2020-12-07 16:19

    You can build a ZIP file containing both using the Maven Assembly plugin.

    You can also use Maven Antrun plugin or similar to put whatever file you want but the idea of single artifact per project is built deep into Maven internals so there is a chance it will hunt you down elsewhere.

    0 讨论(0)
  • 2020-12-07 16:29

    Exclude that file: http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html

    And then use the Maven Antrun plugin to copy the file.

    However, the latter part does not make much sense. If it is a configuration file to put in a server, simply manually copy it.

    0 讨论(0)
  • 2020-12-07 16:38

    No plugin definitions needed, just edit the build resources:

    <build>
        <resources>
            <!-- regular resource processsing for everything except logback.xml -->
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>logback.xml</exclude>
                </excludes>
            </resource>
            <!-- resource processsing with a different output directory
                 for logback.xml -->
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>logback.xml</include>
                </includes>
                <!-- relative to target/classes
                     i.e. ${project.build.outputDirectory} -->
                <targetPath>..</targetPath>
            </resource>
        </resources>
    </build>
    

    Reference:

    • process-resources (Maven Book)
    • <build><resources> (POM Reference)
    0 讨论(0)
提交回复
热议问题