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--- 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.
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.
Files from
target/tests-classes
(by default) are included at the beginning the test classpath. So when running tests, resources from bothsrc/main/resources
andsrc/test/resources
are on the classpath but the later has precedence over the former. In other words, if you have aconfig.xml
insrc/main/resources
and insrc/test/resouces
:src/main/resources/config.xml
will be packaged in the final artefact butsrc/test/resources/config.xml
will be used when running testIf 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