[英]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
. 在过去,每当我从Maven中编译测试代码时,它都会将测试源树中包含的所有* .xml资源文件复制到
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.
每当我通过Maven或Intellij IDEA运行测试时,测试都会失败,因为它在类路径中找不到任何* .xml文件 - 它们从未被复制过。
I have older projects on my computer using exactly the same .pom file and project structure, and the *.xml files copy over fine. 我在我的计算机上使用完全相同的.pom文件和项目结构的旧项目,并且* .xml文件复制得很好。
To solve this problem, I included the following XML to my Maven POM: 为了解决这个问题,我将以下XML包含在我的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. 虽然这解决了这个问题,但我仍然很好奇为什么我不得不告诉Maven手动将测试源树中的* .xml文件复制到我的target / test-classes目录。 Like I said, every other older project in the last 2 years is copying the *.xml files over without me specifying
testResources
. 就像我说的那样,过去两年中所有其他旧项目都是在没有指定
testResources
情况下复制* .xml文件。
What could be causing this behaviour? 什么可能导致这种行为?
您应该将资源文件放在src/test/resources
而不是src/test/java
,这是针对java源文件的。
要控制(也)复制哪些文件,请查看资源插件文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.