Terminal User
Terminal User

Reputation: 883

maven copy multiple files from different resource folders to a single tagert folder

Suppose

file1.txt, file2.txt under src/main/resource/folder1/folder2/

and file3.txt under src/main/resource/folder2/

I want all txt files under target/testFolder/

Can anyone tell me how to do this? Thanks

Upvotes: 1

Views: 6707

Answers (3)

user799188
user799188

Reputation: 14435

On a project we worked on, we followed the Standard Directory Layout, but we had configuration files in subdirectories under src/main/resources similar to

src/main/resources/folder1
src/main/resources/folder2
src/main/resources/folder3

which we wanted to copy over to under src/test/resources (maintaining the structure). We did this

<testResources>
  ...
  <testResource>
    <directory>src/main/resources/folder1</directory>
    <targetPath>folder1</targetPath>
  </testResource>
  <testResource>
    <directory>src/main/resources/folder2</directory>
    <targetPath>folder2</targetPath>
  </testResource>
  ...
</testResources>

Hope this helps.

Upvotes: 2

JBert
JBert

Reputation: 3390

You might want to create a folder src/test/resources and move all your files there. Maven will automatically copy these files to target/test-classes and add them to the classpath.

And since you are creating this folder structure anyhow, simply move those 3 files in the same folder and Maven will work its magic.

EDIT: For more info, see the Maven Standard Directory Layout Introduction.

Upvotes: 1

user620339
user620339

Reputation: 911

Dont know why you dont want to go with the default director structure. but below link and snippet should help you out.

http://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html

<build>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<finalName>${artifactId}-${version}</finalName>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
  <resource>
    <directory>src/main/resources</directory>
  </resource>
</resources>
<testResources>
  <testResource>
    <directory>src/test/resources</directory>
  </testResource>
</testResources>

Notice

 <outputDirectory>target/classes</outputDirectory>
<testOutputDirectory>target/test-classes</testOutputDirectory>

You can configure your own directories in here.

Upvotes: 1

Related Questions