I m facing a issue where test/resource is not picked,but instead jar's main/resource is picked
Scenario is like : Myproject src/test/resources开发者_如何学Go--- have config.xml w which should be needed by abc.jar which is a dependecy in Myproject.
When running test case for Myproject its loading config.xml of abc.jar instead of Myproject test/resources. - I need to know order in which maven pick resources. - Or wat im trying is not possible.
Thanks.
Files from target/tests-classes
(by default) are included at the beginning the test classpath. So when running tests, resources from both src/main/resources
and src/test/resources
are on the classpath but the later has precedence over the former. In other words, if you have a config.xml
in src/main/resources
and in src/test/resouces
:
src/main/resources/config.xml
will be packaged in the final artefact butsrc/test/resources/config.xml
will be used when running test
If this is not what you're experiencing, there must be a mistake somewhere else.
If you want to convince yourself you can run mvn -X test
, this will print the Test Classpath. And you'll see that this classpath is made of (in this order):
target/test-classes
target/classes
- the project jar
- the dependencies (including those with a test scope)
I ran into a similar issue with my project. So I have TestClassA in ProjectA that calls ClassB from ProjectB. ClassB uses a file in src/test/resources. For some reason this file was not being used. I found out that ProjectA had a file by the same name in its src/test/resources.
So in summary, even though ClassB was in ProjectB, it was using ProjectA's src/test/resources because that's the project where the test originated.
精彩评论