Maven: how to place resource file together with jar?

Vladislav Rastrusny picture Vladislav Rastrusny · Apr 12, 2011 · Viewed 48.8k times · Source

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 inside?

So, well, I just want Maven to copy the resource to the same folder where jar will be.

Answer

Sean Patrick Floyd picture Sean Patrick Floyd · Apr 20, 2011

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: