Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maven test classpath

 
Mikael Gyth
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I get an error when i try to run my unittest, because they can't find my resource files.
They are located at:
src/main/resources/Bundle.properties
As I understand it from this post I need to add this path to my test classpath so that it's avaliable to the tests too.
But I can't figure out what file, menu or property i need to edit to set it.
I am using Netbeans 7.2 and Maven for a JSF project.

Can anyone give me som decent instructions on how to add this path to the test classpath in this environment.

Br.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18162
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resources used only by testing should go in src/test/resources, not src/main/resources.

Maven will automatically copy the resources when it runs the tests. You do not have to specify anything.
 
Mikael Gyth
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply.

I don't have any resources used only by testing, only my regular resources that are located in src/main/resources.

I guess I must have something configured wrong in that case, because my test methods can't find the resources.
Do I have to manually create the src/test/resources for maven to copy the files there when the tests run?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18162
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maven copies to the "target" directory when building and when testing. Nowhere else. A "mvn clean" destroys that directory and all its subdirectories".

There are exceptions to src/xxxx/resources if you are building something other than a basic jar. In particular, a WAR build pulls its resources from src/main/webapp, and copies them into the resulting webapp relative to its root (not its /WEB-INF/classes).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic