How to copy resource to src target directory with Maven?

maven copy-resources example
maven-resources-plugin
maven copy resources from dependency
maven resources plugin testresources example
maven copy-resources rename
maven copy-resources overwrite
maven not copying resources to target
maven-shade copy resources

I'm currently working on an existing project which has a pom.xml file with the following:

<resources>
    <resource>
        <filtering>false</filtering>
        <directory>src</directory>
        <includes>
            <include>**/*.properties</include>
        </includes>
    </resource>
</resources>

I have in the base path a directory called properties which contains properties files. I want to copy when packaging all the properties files contains under properties/ in my src directory (otherwise the program will crash due to missing configuration files).

So my question is:

How can i, with Maven include resource files that are not located under src directory?

I try this one but it doesn't seem to work:

<resources>
    <resource>
        <filtering>false</filtering>
        <directory>src</directory>
        <includes>
            <include>**/*.properties</include>
            <include>../properties/**</include>
        </includes>
    </resource>
</resources>

Thank's for your help.


If your file structure is like this: Standard Directory Layout

Then you dont have to add the resources elemt. Maven copies by default all the files and folders that are located in your /src/main/resources folder to your build folder and locates them in the root of your compiled classpath files. if you have for example a file called configuration.properties located in /src/main/resources/configuration.properties then when running mvn clean compile this file will be copied to your /target/classes/configuration.properties So if you remove that part the files will be located where u want them

<resource>
    <filtering>false</filtering>
    <directory>src</directory>
    <includes>
        <include>**/*.properties</include>
    </includes>
</resource>

Apache Maven Resources Plugin – Copy Resources, You can use the mojo copy-resources to copy resources which are not in <​outputDirectory>${basedir}/target/extra-resources</outputDirectory>; <resources​>; <resource>; <directory>src/non-packaged-resources</directory>  Although building a maven project you have to use a specific directory for resources, there are some cases that you have to keep a resource in a different directory. If you put a .properties file in src or into a java package, maven will not copy that file in the target classes directory, so in your deployment package it will not be present.


By migrating of projects from ant to maven without changing project structure set your sourceDirectory testSourceDirectory in the build and use the maven-resource-plugin as folowing take care in wich phase you execute the goals.

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-resources01</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/classes</outputDirectory>
                        <encoding>UTF-8</encoding>
                        <resources>
                            <resource>
                                <directory>${basedir}/src</directory>
                                <includes>
                                    <include>**/*.properties</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
                <execution>
                    <id>copy-resources02</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/build/lib</outputDirectory>
                        <encoding>UTF-8</encoding>
                        <resources>
                            <resource>
                                <directory>${basedir}/target/</directory>
                                <include>*.jar</include>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Apache Maven Resources Plugin – Specifying resource directories, Specifying resource directories. By default, Maven will look for your project's resources under src/main/resources. Project; |-- pom.xml; `-- src  Maven's Surefire (testing) pluginmvn test-compile copies files in src/test/resources to target/test-classes.It compiles .java in src/test/java, and copies the compiled .class files to target/test-classes.


To copy everything from source to destination, I used following

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/classes/static/</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/gui/build/</directory>
                                <includes>
                                    <include>**/*.*</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Maven Copy Resources Example, Here is example of Maven Copy Resources Example with from one <​outputDirectory>${basedir}/target/extra-resources</outputDirectory> <!-- output directory --> <directory>${basedir}/src/main/resources</directory>. A first way is to put the files into src/main/resources that is the folder devoted to store the complied resources, i.e. the resources included into the jar file (e.g. images for the icons). If you need to make the config file to be distributed with the jar, but separated by it, you must edit the pom.xml file.


Maven Resources Plugin Understanding, The 3 variations only differ in how the resource and output directory The resources files are copied from src/main/resources to target/classes :. Here is example of Maven Copy Resources Example with from one location to another location, include files, exclude files. Table of Contents1. Maven Copy Resource from one location to another location2.


Maven copy configuration file or resource in target classes directory , If you put a .properties file in src or into a java package, maven will not copy that file in the target classes directory, so in your deployment  Copy Resources. You can use the mojo copy-resources to copy resources which are not in the default maven layout or not declared in the build/resources element and attach it to a phase


Maven Resources Plugin, Learn about the Maven resources plugin, used to copy files from resource directories to an output directory. I have very straight forward maven project with two idea project modules. When I perform maven install, resources folder is not copied in target output directory. Note- my resources directory contains hibernate.cfg.xml file. Thanks, Jayadip