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>
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/
This works for me in one of my projects:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<!-- when to execute copy operation -->
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${basedir}/pathTo.MD</directory>
</resource>
</resources>
<overwrite>true</overwrite>
<outputDirectory>${project.build.directory}/${project.build.finalName}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
I see that i have the phase and the goal extra from your version. I also used variables for the output location.
I would recommend you to be more equal to this example: http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html
With "more equal" I mean like using <executions>
tag.
You can of course leave out things like <id>
and filtering
.
The following worked fine for me:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>myID</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/extra-resources</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>src</directory>
<!-- Details about filtering: http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html -->
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>