Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven is not copying *.xml files in src/test/java to target/test-classes by default

I have been out of programming for awhile and I'm getting back into it, and I have come across a very peculiar problem. In the past whenever I compiled the test code from within Maven, it would copy over all of my *.xml resource files contained within the test source tree into target/test-classes. But last night, on my current project, it not longer did this - which is not what I expected. Whenever I ran my tests through Maven or Intellij IDEA, the tests would fail because it could not find any *.xml files in the classpath - they never got copied over.

I have older projects on my computer using exactly the same .pom file and project structure, and the *.xml files copy over fine.

To solve this problem, I included the following XML to my Maven POM:

    <testResources>
        <testResource>
            <directory>src/test/java</directory>
            <filtering>false</filtering>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </testResource>
    </testResources>

While this solves the problem, I am still curious why I had to go out of my way to tell Maven to copy *.xml files from my test source tree to my target/test-classes directory manually. Like I said, every other older project in the last 2 years is copying the *.xml files over without me specifying testResources.

What could be causing this behaviour?

like image 792
egervari Avatar asked Sep 12 '13 09:09

egervari


2 Answers

You should put resource files in src/test/resources not src/test/java, which is for java source files.

like image 175
Qwerky Avatar answered Oct 03 '22 05:10

Qwerky


To control which files are (also) copied take a look at the Resource Plugin Documentation

like image 30
Martin Kersten Avatar answered Oct 03 '22 04:10

Martin Kersten