The Resources plugin comes into picture to copy project resources to the output directory. The resources can be for the project to run or for the purpose of testing.
Let's start using the Maven Resources plugin by performing the following steps:
mvn process-resources
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ simple-project --- [INFO] skip non existing resourceDirectory C:projectsapache-maven-cookbooksimple-projectsrcmain esources
When we specify the process-resources
phase, Maven executes the resources
goal of maven-resources-plugin
, which is bound to the process-resources
lifecycle phase.
In the earlier project, there are no resources and hence, resources are not copied.
If you add a file in srcmain
esources
(as in the case of the project-with-resources
project), you will see the following output:
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ project-with-properties --- [INFO] Copying 1 resource
You could also explicitly invoke the plugin's goal as follows:
mvn resources:resources
You could also invoke any phase following the process-resources
phase, which will trigger resource processing as well:
mvn compile
There is a separate goal to copy test resources to provide separation of the main and test resources. Like project resources, the test resource processing can be invoked in three ways, which are as follows:
What if we had resources in additional folders? The Maven Resources plugin allows us to configure these additional folders.
Let's say we have an additional resources folder, namely src/main/additional
. We can configure the pom.xml
file as follows:
<build> <resources> <resource> <directory>src/main/resources</directory> </resource> <resource> <directory>src/main/additional</directory> </resource> </resources> </build>
Now, run the following command:
mvn process-resources
Observe the output:
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ project-with-additional-resources --- [INFO] Copying 1 resource [INFO] Copying 1 resource
The line Copying 1 resource
repeats twice, indicating the copying happening from two folders.
18.119.131.10