Search code examples
javamavenmaven-pluginmaven-resources-plugin

Howto copy README.md into src/main/resources?


I want to show README.md file like help page in my web application. In order not to create duplicate, I need to copy by mvn from project path into resources.

How can I do so?

Any idea?

I have tried:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.3</version>

    <configuration>
        <!-- this is important -->
        <overwrite>true</overwrite>
        <!-- target -->
        <outputDirectory>${basedir}/target/classes</outputDirectory>
        <resources>
            <resource>
                <!-- source -->
                <directory>/</directory>
                <include>
                    <filter>**/README.md</filter>
                </include>
            </resource>
        </resources>
    </configuration>
</plugin>

Solution

  • The simplest solution would be to move the appropriate file(s) to src/main/resources folder whereas the second solution could be like this:

      <build>
        <resources>
          <resource>
            <directory>${project.basedir}</directory>
            <includes>
              <include>README.md</include>
            </includes>
            <filtering>true</filtering>
          </resource>
        </resources>
      </build>
    

    No need for maven-resources-plugin to be configured this can be handled by the usual life cylcle and resource handling. The only thing you might need to adapt is the folder where the README.md is located. If you like having filtering you need to add the <filtering>true</filtering> part as well.

    Copying something via Maven during the build into src/** is in general a bad idea, cause those folders are controled by version control systems which will result in uncommitted changes which you don't like to have.

    Note: It would be wise to check for up-to-date versions of plugins (cause 2.3 is of 2008!). The list of the current plugin versions can be found here: http://maven.apache.org/plugins/