egervari
egervari

Reputation: 22512

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?

Upvotes: 5

Views: 6899

Answers (2)

Martin Kersten
Martin Kersten

Reputation: 5513

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

Upvotes: 1

Qwerky
Qwerky

Reputation: 18405

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

Upvotes: 7

Related Questions