Here is example of Maven Copy Resources Example with from one location to another location, include files, exclude files.

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

Apache Maven Assembly Plugin Usage

 

 

Was this post helpful?

Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *