

Here is example of Maven Copy Resources Example with from one location to another location, include files, exclude files.
Table of Contents
1. Maven Copy Resource from one location to another location
<plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>copy-resources</id> <!-- here the phase you need --> <phase>install</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${basedir}/target/extra-resources</outputDirectory> <!-- output directory --> <resources> <resource> <directory>${basedir}/src/main/resources</directory> <!-- source directory --> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin>
2. Maven copy resource with exclude files
<plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>copy-resources</id> <!-- here the phase you need --> <phase>install</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${basedir}/target/extra-resources</outputDirectory> <!-- output directory --> <resources> <resource> <directory>${basedir}/src/main/resources</directory> <!-- source directory --> <filtering>true</filtering> <excludes> <!--Those files will be excluded--> <exclude>temp</exclude> <exclude>temp1</exclude> </excludes> </resource> </resources> </configuration> </execution> </executions> </plugin>
3. Maven copy resource with include files
Here is example of exclude selected files.
<plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>copy-resources</id> <!-- here the phase you need --> <phase>install</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${basedir}/target/extra-resources</outputDirectory> <!-- output directory --> <resources> <resource> <directory>${basedir}/src/main/resources</directory> <!-- source directory --> <filtering>true</filtering> <includes> <!--Only those files will be included--> <include>Demo.java</include> <include>Demo1.java</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin>
4. Maven copy resource with include + exclude files
<plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>copy-resources</id> <!-- here the phase you need --> <phase>install</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${basedir}/target/extra-resources</outputDirectory> <resources> <resource> <directory>${basedir}/src/main/resources</directory> <filtering>true</filtering> <excludes> <!--Those files will be excluded--> <exclude>temp</exclude> <exclude>temp1</exclude> </excludes> <includes> <!--Only those files will be included--> <include>Demo.java</include> <include>Demo1.java</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin>
References:
Apache Maven Assembly Plugin Usage
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.