EN
Java / Maven - copy embedded in-test resource files to target
5 points
In this short article, we would like to show how to copy resource files located in test/
directory into target/
directory using Maven.
Quick solution:
xxxxxxxxxx
1
2
<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">
3
...
4
<build>
5
...
6
<plugins>
7
...
8
<plugin>
9
<groupId>org.apache.maven.plugins</groupId>
10
<artifactId>maven-antrun-plugin</artifactId>
11
<version>3.1.0</version>
12
<executions>
13
<execution>
14
<phase>generate-sources</phase>
15
<configuration>
16
<target>
17
<mkdir dir="${pom.basedir}/target/test-classes" />
18
<copy todir="${pom.basedir}/target/test-classes">
19
<fileset dir="${pom.basedir}/test" includes="**/*.txt" />
20
</copy>
21
</target>
22
</configuration>
23
<goals>
24
<goal>run</goal>
25
</goals>
26
</execution>
27
</executions>
28
</plugin>
29
...
30
</plugins>
31
</build>
32
</project>