views:

160

answers:

2

Hi!

I'm writing a little Maven application in Eclipse. I store some property files and my application context in the directory src/main/resources.

I now want to make Eclipse use properties in the directory src/test/resources. So when I run and debug the program in Eclipse, these test properties should be used.

Do you know how I could make that happen?

A: 

Try this:

  1. Go to "Run->Run configurations..." (in case of debug "Run->Debug configurations...")
  2. Open Run (Debug) configuration which you use
  3. Open "Classpath" tab
  4. Select "User Entries" and click "Advanced..." on the right
  5. In the opened window select "Add folder", point to your src/test/resources
  6. This folder will appear under "User entries", then you should move it up to make it the first on your classpath
Ivan Yatskevich
The project directory, which also contains src/test/resources/ is already added under the "User Entries".
Bernhard V
src/main/resources goes before src/test/resources on the classpath. Therefore your db.properties from src/main/resources is loaded.
Ivan Yatskevich
A: 

Whether you use the Maven Eclipse Plugin or m2eclipse, src/test/resources precedes src/main/resources on the classpath (more precisely, their output directories). In other words, there is nothing to do, things just works as on the command line.

Pascal Thivent