Gary Greenberg
Gary Greenberg

Reputation: 576

Selective copying maven resources

I have a Java application build under maven. It contains two properties files - application.default.properties and application.properties. The second one suppose to supplement and/or overwrite some properties. I do have also logback.xml file in the same src/main/resources directory. I want to keep logging and default properties in the jar file but move application.properies to the root of the tree. I put the following piece into the build section of my pom.xml

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <targetPath>${user.dir}</targetPath>
            <filtering>false</filtering>
            <includes>
                <include>application.properties</include>
            </includes>
        </resource>
    </resources> 

It does copy the application.properties file as expected, but other two files disappeared from the jar file. Can someone please tell me what I am doing wrong and how to alleviate the problem. P.S. I did browse maven documentation but couldn't find the answer there, so please do not tell me RTFM, but if it is there provide a pointer to it.

Upvotes: 1

Views: 563

Answers (2)

vempo
vempo

Reputation: 3153

What you need is another <resource> section that would include application.default.properties and logback.xml and treat them differently.

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <targetPath>${user.dir}</targetPath>
            <filtering>false</filtering>
            <includes>
                <include>application.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>application.properties</exclude>
            </excludes>
        </resource>
    </resources>
</build>

This copies application.properties into ${user.dir}, and packages everything else from src/main/resources into the output jar.

Upvotes: 2

sorencito
sorencito

Reputation: 2625

You will have to move that specific file you want at the root to another directory.

What you did with the include pattern is implicitly excluding the other files. If you include them, they will be moved as well.

Upvotes: 0

Related Questions