Reputation: 2588
"src/main/resources" vs "src/test/resources"
Do "src/main/resources" get copied to the classpath for tests or only "src/test/resources"? What is the best method to make my main resources also my test resources? Would like to avoid having duplicate config files sitting around.
Upvotes: 3
Views: 2400
Reputation: 66851
as a note, if you have a build/resources/*
section of your pom which manually includes stuff, having that might mean the default src/main/resources are no longer included (i.e. by specifying something, you've lost the default).
So add this in also seemed to fix it:
<resource>
<directory>src/main/resources</directory>
</resource>
Upvotes: 0
Reputation: 9069
Your understanding is correct. When you execute the mvn clean test
, all java classes, test classes, main resources and test resources are generated/copied to the ${basedir}/target/classes
and ${basedir}/target/test-classes
. They are available on the classpath.
Normally the src/main/resources
is a static which will be packed to our artifact. Anyhow they are some use cases that allow the actor to define their resources against our artifact. The src/test/resources
comes to ensure this during the unit testing.
Not only this, but also, we can define any specific for unit testing at src/test/resources
, e.g. arquillian configuration for javaee unit testing.
I hope this may help.
Upvotes: 3