开发者

Why is Maven using test resources in a production build?

In a maven project I have several modules which only have a persitence.xml for unit-tests in

src/test/resources/META-INF/persistence.xml

If I build the project with 'package' the (unit-test) persistence.xml is copied into the jar file.

The created artifact (jar) is not supposed to have any persistence.xml because it is already contained in a war file which includes several modules.开发者_Python百科

The poms are very small and have no plugins configured, everything should be the default behaviour.

  • What am I doing wrong?
  • Is there any documentation available which explains this effect?


When you run Maven with the debug flag, i.e. mvn -X ... do you see any messages indicating that files from src/test are being copied? If so, you might want to check the Maven goal that performs this activity.

Also, you might want to check the contents of the target/classes and target/test-classes directories of the project/module after the Maven build. Assuming that the module has a packaging of jar, the maven-jar-plugin merely picks up the contents of the project's output directory, i.e. target/classes or ${project.build.outputDirectory} while carefully avoiding the project's test output directory, i.e. target/test-classes or ${project.build.testOutputDirectory}. This should also be evident from the output of mvn -X ....

Finally, you might want to check the contents of your local Maven repository for the jar file created. It might so happen that your maven-war-plugin used to create the WAR file, might be picking an older and incorrect version of the JAR that has the test persistence bundled in it, from the local repository.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜