Best practices for copying files with Maven

Joshua Fox picture Joshua Fox · Feb 25, 2009 · Viewed 297.2k times · Source

I have config files and various documents that I want to copy from the dev environment to the dev-server directory using Maven2. Strangely, Maven does not seem strong at this task.

Some of the options:

  • Simple use a copy task in Maven
<copy file="src/main/resources/config.properties" tofile="${project.server.config}/config.properties"/>
  • Use the Ant plugin to execute copy from Ant.

    • Construct an artifact of type zip, alongside the "main" artifact of the POM which is usually of type jar, then unpack that artifact from the repository into the target directory.

    • maven-resources plugin, as mentioned below.

    • Maven Assembly plugin -- but this seems to require a lot of manual definitions, when I want to do things simply and "conventionally."

    • This page even shows how to build a plugin to do copying!

    • maven-upload plugin, as mentioned below.

    • maven-dependency-plugin with copy, as mentioned below.


All these seem needlessly ad hoc: Maven is supposed to excel at doing these standard tasks without fuss and bother.

Any advice?

Answer

peter picture peter · Aug 10, 2009
<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.3</version>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include> **/*.properties</include>
            </includes>
        </resource>
    </resources>
    ...
</build>