简体   繁体   中英

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?

您应该将资源文件放在src/test/resources而不是src/test/java ,这是针对java源文件的。

要控制(也)复制哪些文件,请查看资源插件文档

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM