Languages
[Edit]
EN

Java / Maven - copy embedded in-source resource files to target

9 points
Created by:
Peter-Mortensen
558

In this short article, we would like to show how to copy resource files located in src/ directory into target/ directory using Maven.

Quick solution:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <configuration>
                            <target>
                                <mkdir dir="${pom.basedir}/target/classes" />
                                <copy todir="${pom.basedir}/target/classes">
                                    <fileset dir="${pom.basedir}/src" includes="**/*.txt" />
                                </copy>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
    </build>
</project>

 

See also

  1. Java / Maven - copy embedded in-test resource files to target

  2. Java - get file absolute path according to indicated class

References

  1. Apache Maven AntRun Plugin » 3.1.0
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join