Maven:如何将资源文件与jar一起放置?

Vla*_*sny 29 maven maven-resources-plugin

我有\ src\main\resources\logback.xml文件.当我运行mvn package它时默认放入jar.我怎样让Maven把它放在罐子旁边,而不是放在里面?

所以,好吧,我只是想让Maven将资源复制到jar所在的文件夹中.

Sea*_*oyd 74

无需插件定义,只需编辑构建资源:

<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>
Run Code Online (Sandbox Code Playgroud)

参考: